Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 从ViewModel对象创建视图_Wpf_View_Mvvmcross_Viewmodel - Fatal编程技术网

Wpf 从ViewModel对象创建视图

Wpf 从ViewModel对象创建视图,wpf,view,mvvmcross,viewmodel,Wpf,View,Mvvmcross,Viewmodel,我发现MvvmCross touch支持使用MvxViewModelRequest从ViewModel对象创建视图 但在MvvmCross WPF中,我只能使用 Mvx.Resolve<IMvxSimpleWpfViewLoader>().CreateView(viewmodelRequest) Mvx.Resolve().CreateView(viewmodelRequest) 但是,我找不到从ViewModel对象创建视图的方法?MvvmCross是否支持WPF?默认情况下,

我发现MvvmCross touch支持使用
MvxViewModelRequest
从ViewModel对象创建视图

但在MvvmCross WPF中,我只能使用

Mvx.Resolve<IMvxSimpleWpfViewLoader>().CreateView(viewmodelRequest)
Mvx.Resolve().CreateView(viewmodelRequest)

但是,我找不到从ViewModel对象创建视图的方法?MvvmCross是否支持WPF?

默认情况下,WPF中不包括此功能,但您可以轻松添加它

逻辑类似于中基于请求的代码-类似于:

  // Use `IMvxViewFinder` to find the type of view: 
  var viewType = Mvx.Resolve<IMvxViewFinder>().GetViewType(myViewModel.GetType());

  // create a view and set the data context
  var viewObject = Activator.CreateInstance(viewType);
  if (viewObject == null)
     throw new MvxException("View not loaded for " + viewType);

  var wpfView = viewObject as IMvxWpfView;
  if (wpfView == null)
     throw new MvxException("Loaded View does not have IMvxWpfView interface " + viewType);

  wpfView.ViewModel = myViewModel;
//使用'IMvxViewFinder'查找视图类型:
var viewType=Mvx.Resolve().GetViewType(myViewModel.GetType());
//创建视图并设置数据上下文
var viewObject=Activator.CreateInstance(viewType);
if(viewObject==null)
抛出新的MvxException(“未为“+viewType”加载视图);
var wpfView=作为IMvxWpfView的视图对象;
if(wpfView==null)
抛出新的MvxException(“加载的视图没有IMvxWpfView接口”+视图类型);
wpfView.ViewModel=myViewModel;
如果愿意,您可以将其构建到自定义视图容器或自定义视图演示器中。

假设您有

public partial class LoginViewController : MvxViewController<LoginViewModel>
在哪里

也谢谢@cheesebaron的和

this.presentedCurrentController = Activator.CreateInstance(typeof(LoginViewController)) as LoginViewController;
(this.presentedCurrentController as LoginViewController).ViewModel = new LoginViewModel();
this.presentedCurrentController it's

var NSViewController presentedCurrentController;