Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For me the whole point of using MVVM Light is to avoid injecting anything into the constructor of a View Model. MVVM Light provides a Messaging facility that allows you to send your parameters to a listener registered <em>inside</em> of the View Model.</p> <p>For example, this is my View Model from my <a href="http://wordwalkingstick.codeplex.com/" rel="nofollow">WordWalkingStick</a> project using VSTO and WPF:</p> <pre><code>using System; using System.Xml.Linq; using GalaSoft.MvvmLight.Messaging; namespace Songhay.Wpf.WordWalkingStick.ViewModels { using Songhay.Office2010.Word; using Songhay.OpenXml; using Songhay.OpenXml.Models; using Songhay.Wpf.Mvvm; using Songhay.Wpf.Mvvm.ViewModels; /// &lt;summary&gt; /// View Model for the default Client /// &lt;/summary&gt; public class ClientViewModel : ViewModelBase { /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref="ClientViewModel"/&gt; class. /// &lt;/summary&gt; public ClientViewModel() { if(base.IsInDesignMode) { #region this._flatOpcSourceString = ApplicationUtility .LoadResource( new Uri("/Songhay.Wpf.WordWalkingStick;component/PackedFiles/FlatOpcToHtml.xml", UriKind.Relative)); this._xhtmlSourceString = ApplicationUtility .LoadResource( new Uri("/Songhay.Wpf.WordWalkingStick;component/PackedFiles/FlatOpcToHtml.html", UriKind.Relative)); #endregion } else { this._flatOpcSourceString = "Loading…"; this._xhtmlSourceString = "Loading…"; //Receive MvvmLight message: Messenger.Default.Register(this, new Action&lt;GenericMessage&lt;TransformationMessage&gt;&gt;( message =&gt; { var tempDocFolder = Environment.ExpandEnvironmentVariables("%UserProfile%/Desktop/"); var inputPath = tempDocFolder + "temp.docx"; var outputPath = tempDocFolder + "temp.html"; var flatOpcDoc = XDocument.Parse(message.Content.TransformationResult); OpenXmlUtility.TransformFlatToOpc(flatOpcDoc, inputPath); this.FlatOpcSourceString = flatOpcDoc.Root.ToString(); var settings = new SonghayHtmlConverterSettings() { PageTitle = "My Page Title " + DateTime.Now.ToString("U"), UseEntityMap = false }; OpenXmlUtility.WriteHtmlFile(inputPath, outputPath, settings); var xhtmlDoc = XDocument.Load(outputPath); this.XhtmlSourceString = xhtmlDoc.Root.ToString(); })); } } /// &lt;summary&gt; /// Gets or sets the flat opc source string. /// &lt;/summary&gt; /// &lt;value&gt;The flat opc source string.&lt;/value&gt; public string FlatOpcSourceString { get { return _flatOpcSourceString; } set { _flatOpcSourceString = value; base.RaisePropertyChanged("FlatOpcSourceString"); } } /// &lt;summary&gt; /// Gets or sets the XHTML source string. /// &lt;/summary&gt; /// &lt;value&gt;The XHTML source string.&lt;/value&gt; public string XhtmlSourceString { get { return _xhtmlSourceString; } set { _xhtmlSourceString = value; base.RaisePropertyChanged("XhtmlSourceString"); } } string _flatOpcSourceString; string _xhtmlSourceString; } } </code></pre> <p>You can see that MVVM Light is <em>messaging</em> (not injecting) values into the constructor (<code>Messenger.Default.Register</code>) with its <code>Messenger</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload