This is a migrated thread and some comments may be shown as answers.

TransformToVisual() and Catastrophic failure

2 Answers 151 Views
Window
This is a migrated thread and some comments may be shown as answers.
Nic
Top achievements
Rank 1
Nic asked on 19 Feb 2009, 09:59 PM
Hi,

By looking at the control template I was able to add a button besides the pin/minimise/maximise/close buttons of the RadWindow. I now want to be able to have this button act as a widget so that when clicked on, a popup appears positioned directly under the button as if attached to the button. The user can then interact with whatever content is in the popup.

The problem I'm having is positioning the popup under the button. I'm attempting to use

GeneralTransform transform = btn.TransformToVisual(App.Current.RootVisual);

so that I can obtain the co-ordinates of the button relative to the root visual co-ordinate system but this throws a catastrophic failure. My understanding is that this happens because my RadWindow has not been added to the visual tree, and in fact RadWindow is itself a popup.

So my question is can I just add my RadWindow to the top most ui container in my visual tree when I create the window. On closing the window, I should then remove it from the same container. Would this be the right way to go or am I missing something?

thanks!
Nic


2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo Borisov
Telerik team
answered on 20 Feb 2009, 01:15 PM
Hi Nic,

No, you don't have to add or remove the RadWindow to and from the visual tree because this may cause some interruptions to our  internal layout system for the popup itself. What you can actually do is to get the button's position relative to the RadWindow itself and just use the Left and Top properties of the RadWindow itself to get the absolute position of the button in respect to the root visual. Here is a sample code that I believe should resolve your problem.

RadWindow window = new RadWindow();  
GeneralTransform transform = button.TransformToVisual(window);  
Point pnt = transform.Transform(new Point(window.Left, window.Top));

Or if you inherit the RadWindow, just use "this" instead, and make sure the control template is already applied so your button won't throw "Object reference not set to an instance of an object" whenever referring to it. I hope this will resolve your issue.

Kind regards,
Hristo Borisov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nic
Top achievements
Rank 1
answered on 20 Feb 2009, 05:24 PM
Hristo,

Thanks again for your help on the technique. I was still having a catastrophic failure after applying your changes so I had a look at how my root visual was being setup. It's layout was like this:

<Border Style="{StaticResource ShellBorderStyle}">
                    
            <ScrollViewer x:Uid ="ScrollContainer" x:Name="ScrollContainer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
            
                <StackPanel x:Uid="TheAppLayoutRoot" x:Name="TheAppLayoutRoot" Orientation="Vertical">
                    
                    <!-- ### add ui here. ### -->
                    
                </StackPanel>
            
            </ScrollViewer>
                    
        </Border>

By wrapping the Border itself into a container like StackPanel the problem is resolved. I'm not entirely sure what the root cause is but I recall a past issue arising out of the scrollviewer not being a child of some container. So after doing this, the catastrophic failure is resolved.

Thanks,
Nic
Tags
Window
Asked by
Nic
Top achievements
Rank 1
Answers by
Hristo Borisov
Telerik team
Nic
Top achievements
Rank 1
Share this question
or