WPF中的帧导航 [英] frame navigation in WPF

查看:76
本文介绍了WPF中的帧导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在页面上有一个按钮,该页面已加载到框架(WPF)内.

按钮->页面->镜框

当我单击按钮时,我想在框架(主框架)内打开另一页

我怎样才能做到这一点??请帮忙:)

Hi All,

I have a button on a Page, the Page is loaded inside a Frame (WPF).

Button -> Page - > Frame

When I click on the button I want to open another page inside my Frame (main frame)

how can I do this?? kindly help :)

推荐答案

您可以使用

You can use the VisualTreeHelper class to find the Frame that contains the Page and, set the Source property of the Frame to the new Page.

您可以实现ButtonClick事件处理程序,如下所示:

You can implement the Click event-handler of your Button, as the following:

private void btnChangePage_Click(object sender, RoutedEventArgs e)
{
    // Find the frame.
    Frame pageFrame = null;
    DependencyObject currParent = VisualTreeHelper.GetParent(this);
    while (currParent != null && pageFrame == null)
    {
        pageFrame = currParent as Frame;
        currParent = VisualTreeHelper.GetParent(currParent);
    }

    // Change the page of the frame.
    if (pageFrame != null)
    {
        pageFrame.Source = new Uri("Page2.xaml", UriKind.Relative);
    }
}


这篇关于WPF中的帧导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆