2016-05-19 56 views
1

我試圖創建一個版本的應用程序UWP爲這裏的TipCalc樣本:https://github.com/MvvmCross/MvvmCross-Samples/tree/master/TipCalcMvvmCross與Template10

已經有樣品,它工作正常在UWP版本。但是我試圖使用Template10(https://github.com/Windows-XAML/Template10),並且我無法使這兩個庫一起工作。

MvvmCross希望我修改OnLaunched方法,該方法引用了根Frame。然而,模板10,而不是抽象這種方法暴露OnStartAsync其中有沒有這樣的參考...

有一個在模板10 CreateRootFrame這似乎是初始化mvvmcross應用正確的地方的覆蓋,但是這並未似乎沒有按照我預期的方式工作...

雖然啓動的應用程序DOES導航到適當的頁面,並且似乎也初始化視圖模型(在關聯的VM中的Start方法上的斷點確實碰到),頁面本身是空白的。

比較兩個應用程序的可視化樹透露,雖然從樣品中存在的UWP應用程序有一個框架:

Visual Tree of working app

我Template10應用程序加載模態對話框:

enter image description here

我分叉原始示例項目並添加了模板10版本,如果您想自己嘗試:https://github.com/selaromdotnet/MvvmCross-Samples

其他人能否將MvvmCross與模板10集成?你有什麼想法我做錯了什麼,以及有關使用這兩個庫的最佳做法的任何建議?

+0

我也試圖將start.Start()方法移動到OnStartAsync,但是當我這樣做時,我得到此錯誤:轉換值\「類型\」以鍵入「Template10.Services.SerializationService.JsonSerializationService +容器」時出錯。快速搜索表明這是一個已修復但更新到最新的模板10預覽版本的錯誤,但沒有任何效果,我得到的結果相同 – SelAromDotNet

+0

實際上我錯了,在更新到最新版本時我得不到相同的結果Template10(預覽)版本,但相反,CreateRootElement根本沒有被調用,事實上已經過時,所以我的應用程序永遠不會被初始化,並且我得到一個空引用錯誤。所以肯定失去了這裏,將不勝感激任何見解! – SelAromDotNet

回答

1

嗯事實證明,該ModalDialog是Template10預期的行爲,根據當前文檔的位置:https://github.com/Windows-XAML/Template10/wiki/Docs-|-Bootstrapper

我不夠熟悉Template10說爲什麼是這樣的話,但它也確實說你可以通過覆蓋OnInitializeAsync,我做到了,以同樣的方式定期UWP項目是否恢復原始幀改變這一點:

public override async Task OnInitializeAsync(IActivatedEventArgs args) 
    { 
     Frame rootFrame = Window.Current.Content as Frame; 

     // Do not repeat app initialization when the Window already has content, 
     // just ensure that the window is active 
     if (rootFrame == null) 
     { 
      // Create a Frame to act as the navigation context and navigate to the first page 
      rootFrame = new Frame(); 


      if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) 
      { 
       //TODO: Load state from previously suspended application 
      } 

      // Place the frame in the current Window 
      Window.Current.Content = rootFrame; 
     } 

     if (rootFrame.Content == null) 
     { 
      var setup = new Setup(rootFrame); 
      setup.Initialize(); 
     } 
     await Task.CompletedTask; 
    } 

這並獲得成功!我相信我還有一段路要走(我相信Template10有它自己的恢復狀態的方式,所以我可能不應該這樣做)...

但是這至少改變終於讓我去一個工作應用程序如果你更瞭解我在這裏做錯了什麼或者我應該做什麼,你的意見將不勝感激,謝謝!