TransformToVisual() and Catastrophic failure

3 posts, 1 answers
  1. Nic
    Nic avatar
    32 posts
    Member since:
    Oct 2008

    Posted 19 Feb 2009 Link to this post

    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. Answer
    Hristo Borisov
    Admin
    Hristo Borisov avatar
    298 posts

    Posted 20 Feb 2009 Link to this post

    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.
  3. Nic
    Nic avatar
    32 posts
    Member since:
    Oct 2008

    Posted 20 Feb 2009 Link to this post

    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
Back to Top