c# - Using M-V-VM with WPF, how do I instantiate a Dialog View given a ViewModel? -


I am using MVVM with the dialogue box The process I'm using to create dialogs is as follows:

  • A ViewDodel command wishes to open a dialog.
  • This creates ViewModel for the dialog (we call it DialogViewModel).
  • This then sends ViewModel to the DialogProvider to create the real view. This makes my dialog box testable, because the provider can either provide a real view or a test view.

I have to do all this work, however, currently my DialogProvider solution is to manually modify the view class based on ViewModel's name to use the reflection, Like:

  var viewModelType = viewModel.GetType (); Var dialogTypeName = Regex Change (ViewModelType.Name, "ViewModel $", "Dialog"); Var viewType = Assembly.GetExecutingAssembly (). GetType (dialogTypeName); If throwing a new invalid operation exception ("ViewType == empty)" ("Could not find the view for the given type."); Var dialog = (dialog) view type Gate Configurator (Type. Type Type) .Onk (New Object [0]); conversation. Datacontact = see modell; conversation. Owner = application Present. Manwindo; Return dialog;  

This is sub-symmetric, because viewing the view should be given the same name as the modal, and should be in the same namespace etc.

Ideally I would like to do what I would like to do to do Datamapplet Machinery, similar to using a datatyplopel for a scene, and to select the view based on the datatype attribute of the data template. However, I need to do this in C # code (within the Dialog Provider) I

Is it possible? I like to create a content presener in C # Imagine the stuff, I'm going to get the settings of the Datamapplet, and then to drag the dialog view ???

Eric

Why not just DialogProvider uses a default view which is nothing contained in ContentPresenter in a window.

Then you window with your existing window resources Merges resources (this is your new View MODEL map on YouTube as the YouTubeTront

That is, the ContentPresenter content that you have to do is set from your DialogViewModel to C #, and map to the WPF scenario view to Mapping Enables to do


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -