NavigationWindow单击声音

时间:2010-06-07 04:02:10

标签: c# wpf

我有一个WPF应用程序,它使用导航窗口和框架在xaml页面之间导航。每次它在页面之间发出咔嗒声。有没有办法禁用它?

到目前为止,我已经尝试过这个:

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

}

2 个答案:

答案 0 :(得分:2)

您想要的功能称为CoInternetSetFeatureEnabled,您可以在接受的答案to this question中找到一些其他信息。

由于WPF在引擎盖下使用WebBrowser控件,因此它也适用于Frame控件。

答案 1 :(得分:1)

把它放在你的主要课堂上:

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

然后在你的代码上添加这个(Window Loaded):

CoInternetSetFeatureEnabled(Feature, SetFeatureOnProcess, true);