Getting Silverlight MVVM working with Expression Blend design time data? -
I am a big supporter of the MVVM pattern with Silverlight. Currently I wired the code behind the view ViewModel the ViewModel, I like this:
public partial class SomePage: UserControl {public SomePage () {InitializeComponent (); // a new view modell and layout root word vm = new SomeViewModel (); Layout Root.DataContext = vm; }}
and then all the binding views are handled and all the logic is handled in the ViewModel, as the pattern is intended.
However, to wire them, this means that the designer does not work properly, and I can not use Expression Blend design time data. I know that there are such libraries such as MVVML Lite, which will help in doing all this work, but I do not like to bring a library because it has to deal with "one more thing".
Is there a simple pattern for maintaining designing functionality, especially in Blend, to be wired in MVVM to Silverlight? I have done some googling but there are very old articles and there is so much confusion between WPF and Silverlight and older versions that I have a hard time finding out which to use.
BTW I If this happens, then with VS 2010 on SL4.
There are a few ways you can use
First , sample data of expression and design-time properties (i.e., d datantext) in the designer. In your code, you will be binding just visual model:
if (! DesignerProperties.IsInDesignTool) {var vm = new SomeViewModel (); Layout Root.DataContext = vm; }
second , you can create a special design-time visualization models you can bind instead are:
LayoutRoot.DataContext = Designer Properties. New DesignViewModel (): New MyViewModel ();
Finally , there is another way to manage the data within the visual model. I think it spreads the responsibility for all visual model because they do not like it, but you have more accuracy:
// constructor private widget [] _designData = new [] {new widget ( "Test One "), new widget (" two test ")}; Public MyViewModel () (if (DesignerProperties.IsInDesignTool) {MyCollection = new ObservableCollection & lt; widget & gt; (_DesignData);} Else {MyService.Completed + = MyServiceCompleted; MyService.RequestWidgets ();}} private void Maiswahi full ( object sender, Sinkronsaventarges AE) is {// store loading here}
hope that helps!
Comments
Post a Comment