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

Parent of DropDown control in OutlookBar returns null

3 Answers 96 Views
OutlookBar
This is a migrated thread and some comments may be shown as answers.
Karun
Top achievements
Rank 1
Karun asked on 06 Sep 2016, 10:54 AM

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);
                        }

3 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 08 Sep 2016, 11:28 AM
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.
0
Karun
Top achievements
Rank 1
answered on 09 Sep 2016, 04:16 AM

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".

 

0
Milena
Telerik team
answered on 12 Sep 2016, 10:42 AM
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.
Tags
OutlookBar
Asked by
Karun
Top achievements
Rank 1
Answers by
Milena
Telerik team
Karun
Top achievements
Rank 1
Share this question
or