[英]C# WPF Data exchange between Page in a Frame and MainWindow
In my MainWindow.xaml i have the following code: 在我的MainWindow.xaml中,我有以下代码:
<Frame Name="FrmView" Source="Overview.xaml" NavigationUIVisibility="Hidden" />
In Overview.xaml.cs now i want to acces an ObservableCollection which is declared and initialized in MainWindow.xaml.cs. 在Overview.xaml.cs中,现在我想访问一个在MainWindow.xaml.cs中声明和初始化的ObservableCollection。 Is there any way to gain access to the MainWindow from a Frame/Page ?
有没有办法从框架/页面访问MainWindow?
you could try Window.GetWindow(this) in the page. 你可以在页面中尝试Window.GetWindow(this)。 This should give you the top level window.
这应该会给你顶级窗口。
You need to declare your application like: 您需要声明您的应用程序:
or a resource present in application resource
dictionary, so can be accessed by different windows 或者
application resource
字典中存在的application resource
,因此可以由不同的窗口访问
or like a code-behind variable and get/set it via code and not from XAML. 或者像代码隐藏变量并通过代码获取/设置它而不是来自XAML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.