C# WPF 页面切换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17394365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# WPF page switching
提问by Vojtěch Sajdl
I want to accomplish something like they have in Modern UI for WPF. I have MainWindow : NavigationWindow, which source is page /main.xamland my code in it looks like this:
我想完成一些类似于他们在Modern UI for WPF 中所做的事情。我有MainWindow : NavigationWindow,其来源是 page /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);
}
}
The problem is, that when i switch pages, annoying sound appears. I think it's named "navigation start". Can i prevent it from playing ? Or is there another way to switch pages, that doesn't play it ? Thanks in advance.
问题是,当我切换页面时,会出现烦人的声音。我认为它被命名为“导航开始”。我可以阻止它播放吗?或者有没有另一种切换页面的方法,它不播放?提前致谢。
(sorry if this question is dumb, but I'm new to WPF)
(对不起,如果这个问题很愚蠢,但我是 WPF 的新手)
采纳答案by Marcus Ha?mann
Here is a small workaround. Original sources I found here: http://social.msdn.microsoft.com/Forums/vstudio/en-us/843677f4-8f0b-46cb-986c-92e8042d0707/stupid-problem-with-webbrowser-control
这是一个小的解决方法。我在这里找到的原始来源: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("",""));
}
}
}

