你SettingsViewModel
要繼承IFileOpenPickerContinuable
,
public class SettingsViewModel : Screen, IFileOpenPickerContinuable
幀與查看相關的一些情況不是視圖模型 因此,你應該添加自定義方法,這個工作:
加入ContinuationManager.cs
internal void Continue(IContinuationActivatedEventArgs args, IFileOpenPickerContinuable filepickerPage)
{
if (args == null)
throw new ArgumentNullException("args");
if (this.args != null && !handled)
throw new InvalidOperationException("Can't set args more than once");
this.args = args;
this.handled = false;
this.id = Guid.NewGuid();
if (wabPage == null)
return;
switch (args.Kind)
{
case ActivationKind.PickFileContinuation:
if (filepickerPage != null)
{
filepickerPage.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
}
break;
case ActivationKind.PickSaveFileContinuation:
break;
case ActivationKind.PickFolderContinuation:
break;
case ActivationKind.WebAuthenticationBrokerContinuation:
break;
}
}
確保是從
var settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();
返回SettingsViewModel是同一個實例那個叫PickSingleFileAndContinue
,否則將無法正常工作,將繼續暫停,並等待着什麼返回控制。
然後在App.xaml.cs您可以添加:
protected override void OnActivated(IActivatedEventArgs e)
{
base.OnActivated(e);
// Add all of the Frame code
var continuationEventArgs = e as IContinuationActivatedEventArgs;
continuationManager = new ContinuationManager();
SettingsViewModel settingsPage = SimpleIoc.Default.GetInstance<SettingsViewModel>();
if (continuationEventArgs != null)
{
continuationManager.Continue(continuationEventArgs, settingsPage);
}
}
但我要重複代碼OnLaunched?
沒有,只有OnActivate代碼應該叫外,其餘應保持原樣(但你可以做任何你想要的)
我tryed重複從OnLaunched()的所有代碼,它工作正常...當OnActivated()被調用時,也許rootFrame是空的......但是我應該重複OnLaunched的代碼嗎? – sahap 2015-03-31 16:04:21