wpf - In C#, how can I set DataContext on a View from the ViewModel? -


I'm trying to wrap my head around "MVVM. I understand it a lot, but I understand one Difficulty getting into the aspect: Setting DataContext .

I want to show a scene with a particular object. The user does not have to decide what to look like So, I'll have to create a scene in it code. Then, I can see the object's data syntax I'm trying to set the code to bind it. I am trying to not put the code in the view for this, but see the layout root. Datacontext is not public.

What do I miss ?

Trying to avoid it:

  See public class {public view (object datacentext) {InitializeComponent (); LayoutRoot.DataContext = dataContext;}}  

Something like this:

  public class ViewModel {... public UIElement GetView () {UI Element * element = new View (); Element.LayoutRoot.DataContext = element; Return element;}}  

Do not forget that the view is aware of ViewModel Should not, and not

So to make a scene in your case, it's not the best way by putting the code in ViewModel.

Look at MSWM near Josh Smith ViewModel He has advised to use WPF datamapple to select his view in XAML.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -