My MvvmCross app uses a custom presenter that creates a SplitView when run on an Ipad. Both master and detail contain a navigation controller. This works fine except that I don't know how to hint the system where I want the next view to show. I have a couple of views that sometimes should be shown in the detail view and sometimes in the master. If run on an iPhone they will be shown in the single navigation controller.

So in the ViewModel I would like to hint where to put the next view. Something like

ShowViewModel(paramObject, ShowInMaster);

If run on an iPhone the ShowInMaster will be ignored.

Is this possible or am I perhaps doing this all wrong?

有帮助吗?

解决方案

There's an optional presentationBundle parameter you can use in most of the ShowViewModel overrides - see https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxNavigatingObject.cs#L39

You can create a bundle simply from a Dictionary<string,string>() - e.g. you could use new MvxBundle(new Dictionary<string,string>() { { "ShowSplit":"true" } })

When used, this presentation bundle will get placed into the MvxViewModelRequest - in the public IDictionary<string, string> PresentationValues { get; set; } member - see https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelRequest.cs#L33

The request will then get passed to your UI presenter (aka the 'navigation service' in other frameworks) - and your custom code in the presenters on each platform can then decide what to do with these 'presentation' hints - e.g. it can override public override void Show(MvxViewModelRequest request) to inspect the presentation hint contents and to then do some custom split view display (see https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Touch/Views/Presenters/MvxTouchViewPresenter.cs#L45 for the default behaviour)

If it helps, a simple split view display (using fixed logic rather than presentation hints) is in N=24 of http://mvvmcross.blogspot.com

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top