ManfredP
ManfredP

Reputation: 1057

C# WPF Data exchange between Page in a Frame and MainWindow

In my MainWindow.xaml i have the following code:

<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. Is there any way to gain access to the MainWindow from a Frame/Page ?

Upvotes: 3

Views: 1249

Answers (2)

hbarck
hbarck

Reputation: 2944

you could try Window.GetWindow(this) in the page. This should give you the top level window.

Upvotes: 1

Tigran
Tigran

Reputation: 62248

You need to declare your application like:

  • or a resource present in application resource dictionary, so can be accessed by different windows

  • or like a code-behind variable and get/set it via code and not from XAML.

Upvotes: 0

Related Questions