[英]How to get the other control of WPF having same parent in c# without its name proprty?
[英]Get the name of the parent user control WPF C#
我可以訪問用戶控件A.我想獲得有關用戶控件C的信息。有沒有辦法在WPF中執行此操作? 結構基本上就是你所看到的。 用戶控件D是功能區,C是功能區上的選項卡,B和A是C的內容。我似乎無法訪問C.我嘗試使用A的Parent屬性但它似乎沒有給出我關於C.的信息
嘗試使用VisualTreeHelper.GetParent
或在此處使用遞歸函數
也許您可以嘗試將父級轉換為UserControl C,如下所示:
(this.Parent as UserControlC).YourProperty
在Loaded事件處理程序中使用Window.GetWindow(this)方法。
public MainView()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainView_Loaded);
}
void MainView_Loaded(object sender, RoutedEventArgs e)
{
Window parentWindow = Window.GetWindow(this);
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.