I have 2 window in wpf application. There is a frame in window1. I want to change frame source from window2. can you help me?
for example: window 1:
<frame x:name="frame1"/>
window2.cs :
private void button1_click(object sender, RoutedEventArgs e){
window1.frame1.source = new Uri("page1.xaml",UriKind.Relative);
}
Set the FieldModifier attribute of the Frame to internal
or public
or expose the Frame through a property in Window1:
<Frame x:Name="frame1" x:FieldModifier="public" />
You can then get a reference to Window1 and access the field or property using the Application.Current.Windows
collection:
private void button1_click(object sender, RoutedEventArgs e)
{
Window1 window1 = Application.Current.Windows.OfType<Window1>().FirstOrDefault();
if (window1 != null)
{
window1.frame1.Source = new Uri("page1.xaml", UriKind.Relative);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With