C#WPF页面切换
本文关键字:C#WPF | 更新日期: 2023-09-27 18:20:25
我想完成一些类似于他们在用于WPF的现代UI中所做的事情。我有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);
}
}
问题是,当我切换页面时,会出现恼人的声音。我认为它被命名为"导航启动"。我能阻止它播放吗?或者还有其他不播放的切换页面的方法吗?提前谢谢。
(很抱歉,如果这个问题很愚蠢,但我是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("",""));
}
}
}