tags:

views:

116

answers:

1

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);
}

}

A: 

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.

Josh Einstein
I have updated my question with some code. Did I do something wrong because I still hear the clicking?
Robert
Is it IE7 or higher? That should work but maybe you need to do it after the WebBrowser control has loaded. It may need to initialize something else in urlmon first. The only other thing I can suggest is I've seen the DllImport specify ExactSpelling=true but I can't imagine why that would apply here.
Josh Einstein
I'm running IE8. Setting the ExactSpelling=true doesn't work. How would I know when the WebBrowser control has loaded to add this code?
Robert