【问题标题】:How to add the OnShareTargetActivated() method manually in a windows 8 C# blank application?如何在 Windows 8 C# 空白应用程序中手动添加 OnShareTargetActivated() 方法?
【发布时间】:2013-04-19 15:16:11
【问题描述】:

我创建了一个 Windows8 空白 xaml 应用程序。现在我想将此应用程序设置为共享目标。我已按照以下链接中的说明进行操作,并且能够将其设置为目标应用程序。

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh973053

但是我在空白的 xaml 应用程序中在哪里添加以下方法(OnShareTargetActivated)?当我在 mainpage.xaml.cs 中手动添加此方法时,它会显示错误“

“Project.MainPage.OnShareTargetActivated(Windows.ApplicationModel.Activation.ShareTargetActivatedEventArgs)' 是密封类中的新虚拟成员”

“Project.MainPage.OnShareTargetActivated(Windows.ApplicationModel.Activation.ShareTargetActivatedEventArgs)”:找不到合适的方法来覆盖“

 protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
 {
   // Code to handle activation goes here. 
}

【问题讨论】:

  • 您检查了示例应用程序吗? link
  • 我得到了答案。它需要添加到 app.xaml.cs 文件中。

标签: windows-8 microsoft-metro windows-runtime


【解决方案1】:

它位于从 Windows.UI.Xaml.Application 继承的类中。通常是 App.cs。

例如

sealed partial class App : Application
{
    public App()
    {
        this.InitializeComponent();
    }

    //...

    protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
    {
        var rootFrame = new Frame();
        rootFrame.Navigate(typeof(MainPage), args.ShareOperation);
        Window.Current.Content = rootFrame;
        Window.Current.Activate();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 2017-07-12
    • 2012-06-13
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    相关资源
    最近更新 更多