【问题标题】:Adding items to Windows 8 Settings Charms Bar将项目添加到 Windows 8 设置超级按钮栏
【发布时间】:2014-02-09 02:32:10
【问题描述】:

我想在“设置”超级按钮栏中添加一个名为“隐私政策”的按钮,该按钮链接到该网址:

    http://yourdomain.com/privacypolicy

我正在使用 Visual Studio 和 VB 创建一个 Windows 8 应用程序

【问题讨论】:

    标签: vb.net windows-8 hyperlink privacy charms-bar


    【解决方案1】:

    在 app.xaml.cs 中

    protected override void OnWindowCreated(WindowCreatedEventArgs args)
    {
        SettingsPane.GetForCurrentView().CommandsRequested += (s, e) =>
        {
            SettingsCommand defaultsCommand = new SettingsCommand("privacy", "Privacy Policy",
                (handler) =>
                {
                    //open the URL
                    Launcher.LaunchUriAsync(new Uri("http://yourdomain.com/privacypolicy"));
                });
            e.Request.ApplicationCommands.Add(defaultsCommand);
        };
    
        base.OnWindowCreated(args);
    }
    

    【讨论】:

    • 我在创建项目项目时使用了 Visual Basic 项目模板而不是 C# 项目模板,因此我没有 App.xaml.cs - 我只有 App.xaml.vb。 stackoverflow.com/questions/8976597/…
    • 对不起,我的错。但是为 VB 重写该代码应该不会那么难!试一试。
    • 这是我现在得到的:'错误 1'Public Event SettingsPane()' 是一个事件,不能直接调用。使用 'RaiseEvent' 语句来引发事件'
    【解决方案2】:

    App.xaml.vb 文件中的 vb 代码:

        Imports Windows.UI.ApplicationSettings
    

    放置在onlaunched sub中

        AddHandler SettingsPane.GetForCurrentView.CommandsRequested, Sub(sender, e)         e.Request.ApplicationCommands.Add(New SettingsCommand("privacy", "Online Privacy Policy", Sub() privacyGo()))
    

    创建一个子

        Private Sub privacyGo()
    
        Dim privacy As New Uri("http://myprivacy.com")
    
        Windows.System.Launcher.LaunchUriAsync(privacy)
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多