I have a WPF application that uses the navigation window and frames to navigate between xaml pages. Every time it goes between the pages it makes a click sound. Is there a way to disable that?
So far I have tried this:
namespace FrameTesting
{
public partial class MainWindow : NavigationWindow
{
private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
private const int SET_FEATURE_ON_THREAD = 0x00000001;
private const int SET_FEATURE_ON_PROCESS = 0x00000002;
private const int SET_FEATURE_IN_REGISTRY = 0x00000004;
private const int SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008;
private const int SET_FEATURE_ON_THREAD_INTRANET = 0x00000010;
private const int SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020;
private const int SET_FEATURE_ON_THREAD_INTERNET = 0x00000040;
private const int SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080;
public MainWindow()
{
int feature = FEATURE_DISABLE_NAVIGATION_SOUNDS;
CoInternetSetFeatureEnabled(feature, SET_FEATURE_ON_PROCESS, true);
InitializeComponent();
}
[DllImport("urlmon.dll")]
[PreserveSig]
[return: MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(
int FeatureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);
}
}
The function you want is called CoInternetSetFeatureEnabled and you can find some additional information in the accepted answer to this question .
Since WPF uses the WebBrowser control under the hood, this should work for the Frame control as well.
Put this on your main class:
private const int Feature = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDS
private const int SetFeatureOnProcess = 0x00000002;
[DllImport("urlmon.dll")]
[PreserveSig]
[return: MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(int featureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);
And then add this on your code (Window Loaded):
CoInternetSetFeatureEnabled(Feature, SetFeatureOnProcess, true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.