I have access to User Control A. I want to get info on User Control C. Is there any way to do this in WPF? The structure is basically what you see. User Control D is a ribbon, C is a tab on the ribbon and B and A are contents of C. I can't seem to get access to C. I tried using the Parent property of A but it doesn't seem to give me the info on C.
Asked
Active
Viewed 2.6k times
21
-
What does the `Parent` property give you instead? – Drew McGowen Jul 12 '13 at 20:20
-
1I think it gives the window or some other obscure element. The program is ridiculously complicated. – DotNetRussell Jul 12 '13 at 20:24
-
1Are you using MVVM? If not I would recommend using this approach. This way you can get access to the base logic (View Models) under neath without trying to jump across controls directly. – tsells Jul 12 '13 at 20:24
-
Can you cast the Parent Window to Control C? – Jul 12 '13 at 20:25
-
11+1 for the beautiful illustration! :) – Jul 12 '13 at 20:25
3 Answers
18
Try using VisualTreeHelper.GetParent
or use the recursive function here
-
-
This does work however it turns out this question doesn't solve my problem. Checkmark and +1 for right answer though! Thanks – DotNetRussell Jul 15 '13 at 12:38
3
Maybe you can try to cast the parent as UserControl C, like this:
(this.Parent as UserControlC).YourProperty

Guilherme H. J.
- 79
- 3
-1
use the Window.GetWindow(this) method within Loaded event handler.
public MainView()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainView_Loaded);
}
void MainView_Loaded(object sender, RoutedEventArgs e)
{
Window parentWindow = Window.GetWindow(this);
...
}

Mehdi Benkirane
- 437
- 4
- 7