主机监听页面按钮点击事件
Main Frame Listening to Page Button Click Event
我有一个 Main Window,它是在我的项目中显示不同页面的框架,我想在单击页面上的按钮时更改框架中的页面。
问题是我似乎无法让框架包含单击按钮时的事件处理程序,它似乎是页面本身的本地事件。有没有一种方法可以让框架查看页面按钮何时被单击并相应地更改页面?
Main.Content = new Page.Intro();
然而,当按钮 Next
在 Page.Intro()
内被点击时,我想在 Main Window Class
内显示
Main.Content = new Page.Home(userinformation);
我尝试遵循 这与我想要实现的目标类似,尽管我的页面有我需要传递的参数所以我无法调用 MainContent.Source = new Uri("Home.xaml", UriKind.Relative);
因为没有在哪里传递 userinformation
.
as there is no where to pass userinformation
Navigate
方法不仅采用 Uri
,它还有 an overload 以对象作为参数。所以这对你有用
//button click in Page.Intro
private void Button_Click(object sender, RoutedEventArgs e)
{
this.NavigationService?.Navigate(new Page.Home(userinformation));
}
我有一个 Main Window,它是在我的项目中显示不同页面的框架,我想在单击页面上的按钮时更改框架中的页面。
问题是我似乎无法让框架包含单击按钮时的事件处理程序,它似乎是页面本身的本地事件。有没有一种方法可以让框架查看页面按钮何时被单击并相应地更改页面?
Main.Content = new Page.Intro();
然而,当按钮 Next
在 Page.Intro()
内被点击时,我想在 Main Window Class
内显示
Main.Content = new Page.Home(userinformation);
我尝试遵循 MainContent.Source = new Uri("Home.xaml", UriKind.Relative);
因为没有在哪里传递 userinformation
.
as there is no where to pass userinformation
Navigate
方法不仅采用 Uri
,它还有 an overload 以对象作为参数。所以这对你有用
//button click in Page.Intro
private void Button_Click(object sender, RoutedEventArgs e)
{
this.NavigationService?.Navigate(new Page.Home(userinformation));
}