【问题标题】:Main Frame Listening to Page Button Click Event主框架监听页面按钮点击事件
【发布时间】:2019-01-21 02:44:37
【问题描述】:

我有一个主窗口,它是在我的项目中显示不同页面的框架,我想在单击页面上的按钮时更改框架中的页面。

问题是我似乎无法让 Frame 包含单击按钮时的事件处理程序,它似乎是页面本身的本地事件。 Frame 是否有办法查看何时单击页面的按钮并相应地更改页面?

Main.Content = new Page.Intro();

但是,当在Page.Intro() 内点击按钮Next 时,我想在Main Window Class 内显示

Main.Content = new Page.Home(userinformation); 

我尝试关注How to click a button of the page to change the source of the frame of Windows?,这与我想要实现的目标类似,尽管我的页面有我需要传递的参数,所以我不能调用MainContent.Source = new Uri("Home.xaml", UriKind.Relative);,因为没有地方可以传递userinformation .

【问题讨论】:

    标签: c# wpf master-pages


    【解决方案1】:

    因为没有地方可以传递用户信息

    Navigate 方法不仅接受一个Uri,它还有一个接受对象作为参数的an overload。所以这对你有用

    //button click in Page.Intro
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        this.NavigationService?.Navigate(new Page.Home(userinformation));
    }
    

    【讨论】:

    • 非常感谢!完美解决我数周以来一直在努力解决的问题。
    • @Explorex 欢迎您。问号是用来防止空引用的,我提到这一点是因为它对你来说可能看起来很奇怪。
    猜你喜欢
    • 2016-09-03
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 2022-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多