[英]Sharing target Universal Apps Windows 10 approach
I am struggling with it for a few hours and can't find working solution. 我正在努力工作几个小时,找不到工作的解决方案。 My app is a target app for sharing and the problem is when it's running and user wants to share content.
我的应用程序是用于共享的目标应用程序,问题在于它正在运行且用户想要共享内容。
protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
await OnInitializeAsync();
if (await CheckToken(args) != true) return;
if (args.PreviousExecutionState != ApplicationExecutionState.Running)
{
if (await LoadData(args) != true) return;
}
var frame = new Frame();
var navigationService = new NavigationService(_dispatcherService) { RootFrame = frame, };
Window.Current.Content = frame;
Window.Current.Activate();
navigationService.Navigate<ShareViewModel>(args.ShareOperation);
}
The problem is that I can't use frame from running application because I get an exception "marshalling thread ...." so I create a new frame and I assign it to Window.Current.Content. 问题是我无法使用运行应用程序的框架,因为我得到一个异常“编组线程....”所以我创建了一个新框架,并将其分配给Window.Current.Content。 This works fine but the problem is when user finishes sharing.
这工作正常,但问题是用户完成共享。 What should I do?
我该怎么办? It seems that I should assign previous frame to Window.Current.Content which was "overriden" by sharing target right?
看来我应该将前一帧分配给Window.Current.Content,它是通过共享目标来“覆盖”的吗? While I try to do it I get again "marshalling thread" exception.
当我尝试这样做时,我再次获得“编组线程”异常。 If I don't do it then I can't interact with my application because I get an exception that app is being closed.
如果我不这样做,那么我无法与我的应用程序进行交互,因为我得到一个例外,即应用程序正在关闭。 What is the proper scenario for being a sharing target?
作为共享目标的正确方案是什么?
Edit: I guess it's important to mention that I call ReportStarted() when I send message in ShareViewModel and ReportCompleted() when I am done. 编辑:我想重要的是要提到我在完成后在ShareViewModel和ReportCompleted()中发送消息时调用ReportStarted() 。
Exception thrown when I try to assign frame back: {"The application called an interface that was marshalled for a different thread.\\r\\n\\r\\nFailed to initialize the application's root visual"} 当我尝试分配帧时抛出异常: {“应用程序称为为不同线程编组的接口。\\ r \\ n \\ r \\ n无法初始化应用程序的根视觉”}
I'm pasting the solution which solved the issue. 我正在粘贴解决问题的解决方案。 I think the key here is to use
我认为这里的关键是使用
CoreWindow.GetForCurrentThread().Dispatcher
CoreWindow.GetForCurrentThread()。调度员
protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
await OnInitializeAsync();
if (await CheckToken(args) != true) return;
if (args.PreviousExecutionState != ApplicationExecutionState.Running)
{
if (await LoadData(args) != true) return;
}
var frame = new Frame();
Window.Current.Content = frame;
var dispatchService = new DispatcherService() { Dispatcher = CoreWindow.GetForCurrentThread().Dispatcher };
var navigationService = new NavigationService(dispatchService) { RootFrame = frame };
navigationService.Navigate<ShareViewModel>(args.ShareOperation);
Window.Current.Activate();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.