Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think what Thomas was saying is that you could have the following in your Window's codebehind:</p> <pre><code>public partial class MyWindow : Window { ViewModel _vm; public MyWindow(ViewModel vm) { InitializeComponent(); _vm = vm; _vm.Output.CollectionChanged += Output_CollectionChanged; } void Output_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { foreach(object item in e.NewItems) { outputTextBox.AppendText(item.ToString()); } } } </code></pre> <p>This way, the window class will automatically append any text that is added to the Output collection.</p> <p>Another way to do it (though it may not be considered pure MVVM) is by using an interface as follows:</p> <pre><code>public interface IAppendOutput { void Append(string text); } public partial class MyWindow : Window, IAppendOutput { public MyWindow() { InitializeComponent(); } public void Append(string text) { outputTextBox.AppendText(text); } } public class ViewModel { IAppendOutput _outputter; public ViewModel(IAppendOutput outputter) { _outputter = outputter; } public void AppendOutput(string text) { _outputter.Append(text); } } </code></pre> <p>Then in your main app:</p> <pre><code>... MyWindow window = new MyWindow(); ViewModel vm = new ViewModel(window); window.DataContext = vm; window.Show(); vm.AppendOutput("This is a test."); ... </code></pre> <p>This way may not be the best way of doing it, but it may be a useful method for writing quick duct-tape code for other circumstances. It is still unit-testable because the ViewModel has no knowledge of the window itself, only an interface. It is still flexible because you can customize any sort of object so that it implements the IAppendOutput interface.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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