繁体   English   中英

C#WPF页面切换

[英]C# WPF page switching

我想完成类似WPF的Modern UI中的操作 我有MainWindow:NavigationWindow ,其来源是页面/main.xaml ,其中的代码如下所示:

public partial class main : Page
{
    public main()
    {
        InitializeComponent();
    }

    private void settings_Click(object sender, RoutedEventArgs e)
    {
        settings settingsmenu = new settings();
        this.NavigationService.Navigate(settingsmenu);
    }
}

问题是,当我切换页面时,会出现烦人的声音。 我认为它的名称为“导航开始”。 我可以阻止它播放吗? 还是有另一种无法播放页面的方式? 提前致谢。

(很抱歉,这个问题很愚蠢,但我是WPF的新手)

这是一个小解决方法。 我在这里找到的原始资源: http : //social.msdn.microsoft.com/Forums/vstudio/en-us/843677f4-8f0b-46cb-986c-92e8042d0707/stupid-problem-with-webbrowser-control

using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class Page1 : Page
    {
        private RegistryKey regKeyCurrentUser;
        private RegistryKey regSubKeyCurrent;

        public Page1()
        {
            InitializeComponent();
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var page2 = new Page2();
            this.NavigationService.Navigate(page2);
        }

        private void Page1_OnLoaded(object sender, RoutedEventArgs e)
        {
            regKeyCurrentUser = Registry.CurrentUser;
            regSubKeyCurrent = regKeyCurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current", true);
            regSubKeyCurrent.SetValue("", "");
        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            var regSubKeyDefault = regKeyCurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Default");
            regSubKeyCurrent.SetValue("", regSubKeyDefault.GetValue("",""));
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM