Parent of DropDown control in OutlookBar returns null

4 posts, 0 answers
  1. Karun
    Karun avatar
    2 posts
    Member since:
    Sep 2016

    Posted 06 Sep Link to this post

    In my application, I have a outlook bar which has some menu items. On click event of mneu Item I want to traverse the visual tree upto main Window. For normal view of Outlook bar it is working properly but for collapsed view of outlook bar when I click menu item it traverse till PopUpRoot control only. Parent of this control returns null.

     

    var parent = VisualTreeHelper.GetParent(this);
                            while (!(parent is Window))
                            {
                                parent = VisualTreeHelper.GetParent(parent);
                            }

  2. Milena
    Admin
    Milena avatar
    201 posts

    Posted 08 Sep Link to this post

    Hi Karun,

    When the OutlookBar is minimized its content is hosted in a popup and you should have in mind that the popup is in another visual tree, this means that you cannot get to the main window this way.
    I'm not sure about your scenario, but if you need to get the main window, you can try using this code-snippet: 
    var window =  Window.GetWindow(sender as DependencyObject);

    I hope this information helps.

    Regards,
    Milena
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Karun
    Karun avatar
    2 posts
    Member since:
    Sep 2016

    Posted 08 Sep in reply to Milena Link to this post

    Hi Milena,

    Thanks for your suggestion!!!

    But in my scenario, I have a outlookbar control which hosts a button as a outlookbar item. On click event of button I have to find out the coordinates of that button relative to my main Window. I have used TransformToAncestor(Application.Current.MainWindow) function to achieve this. This logic works fine when outlookbar is not minimized. But in minimized view TransformToAncestor() function throws an exception "The Specified visual is not an ancestor of this visual".

     

  5. Milena
    Admin
    Milena avatar
    201 posts

    Posted 12 Sep Link to this post

    Hi Karun,

    This behavior is expected. As I said the Popup is in another VisualTree. I can suggest you to check in the click event if the OutlookBar is minimized and to have 2 different approaches when it is minimized (the content of the OutlookBarItem is hosted in a popup in this case) and when not. For your convenience I've attached a sample project where you can find 2 possible solutions for this scenario:
    1. You can get the first child of  the popup and calculate its position according to the position of the DropDownButton (Minimized Button)
    2. You can simply get the mouse position on click if this is suitable for your scenario.

    Please take a look at the project and let us know if this works for you.

    Regards,
    Milena
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top