如何在Windows 8 C#blank应用程序中手动添加OnShareTargetActivated()方法?

时间:2012-09-07 08:23:48

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

我创建了一个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. 
}

1 个答案:

答案 0 :(得分:0)

它继承自Windows.UI.Xaml.Application的类。通常是App.cs.

E.g。

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