mvvm light - Set Up INavigation with Xamarin.Forms and MVVMLight IOC -


I'm using MAVVML for XMERIN. IOC set up to create my first content page in the form and app Need some help to get .GetMainPage.

My ViewModels have such constructors -

  public class newstype 1ViewModel: ViewModelBase {Private Readonly IContentService contentService; Private Readonly Invention Navigation; Public listing & lt; ContentModel & gt; Receive {content; Set; } Public Notatip 1 View Model (Navigation Navigation, IContent Services Service Services) {this.contentService = contentService; this. Navigation = Navigation; }  

My content pages have constructors -

  public partial class news type 1CP: content page {private newstype 1 viewmodel vm; Public Noutip 1CP (NewsTip 1ViewModel vm) {InitializeComponent ();  

I am using a ViewModelLocator class as the following -

  Public class ViewModelLocator {Public ViewModelLocator () {ServiceLocator.SetLocatorProvider (() = & Gt; SimpleIoc defaults); // service if (apps.probboad) {simplecok.default. Registrar & lt; IContentService, ContentServiceStub & gt; (); } Other {Simple} IOC. Default. Registrar & lt; IContentService, ContentService & gt; (); } // How do I wire the navigation? // I can not just register the default navigation page () because it has 2 / possible constructors, so my derived class SimpleIoc.Default.Register & lt; Inagigation, AppNavigationPage & gt; Attempted on [favorite designer]. (); // View Model SimpleIoc.Default.Register & lt; NewsType1ViewModel & gt; (); SimpleIoc.Default.Register & LT; NewsDetailsViewModel & gt; (); } Public Newsplay 1ViewModel NewsType1ViewModel {Return Servers. Current. GetInstance & lt; NewsType1ViewModel & gt; (); }} Public News Viveham News WidgetModel {Return Service Sector. (); }} Public class AppNavigation page: Navigation Page {[Configure Configure] Public App Navigation Page My App.cs  "In Progress"  is as follows -  
  Public Static Class app { Public static AppNavigationPage Nav; Public static ViewModelLocator locator = new ViewModelLocator (); Public Stable Boole StubMode = True; Public static page GetMainPage () {try} // Want to return a nav with NewsType 1CP as the starting page. News News Type 1CP = New NewsTip 1CP (Service Locker Current.GetInstance & lt; NewsType 1ViewModel & gt; ()); Nav.PushAsync (newsType1CP); Return NAV; } Hold (exception preceding) {// exception baseexception = ex.GetBaseException (); Debug.lightline (base option message); } Return tap; }}  

My latest exception is -

The destination type can not be entered from the source type.

Am I trying to supply an injury to each visual model, like tilt the wrong tree?

Update: After some replies, showing other ways of controlling navigation in the xorman form, I think that if someone can explain why navigation Trying to construct a constructor is not such a good thing.

I think my example is a bit confusing as a static situation with AppNavigationPage, ideally I would also like to be in IOC too, so I can just return the service service. Current.GetInstance & lt; AppNavigationPage> (), but I had to go with different factory methods and it was in the midst of debugging, so the code is clearly half-baked ...

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

c# - Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query for nullable types -

cmake - cpack generates RPMs with %files entries that conflict with the RPM spec. How to fix? -