Sharing data between different ViewModels
<p>I'm trying to develop an easy MVVM project that it has two windows:</p>
<ol>
<li><p>The first window is a text editor, where I bind some properties such as <code>FontSize</code> or <code>BackgroundColor</code>:</p>
<p><code>&lt;TextBlock FontSize=&quot;{Binding EditorFontSize}&quot;&gt;&lt;/TextBlock&gt;</code></p>
</li>
</ol>
<p>its <code>DataContext</code> is <strong>MainWindowViewModel</strong>:</p>
<pre><code>public class MainWindowViewModel : BindableBase
{     
    public int EditorFontSize
    {
        get { return _editorFontSize; }
        set { SetProperty(ref _editorFontSize, value); }
    } 
.....
</code></pre>
<ol start="2">
<li>The second window is the option window, where I have an slider for changing the font size:</li>
</ol>
<p><code>&lt;Slider Maximum=&quot;30&quot; Minimum=&quot;10&quot; Value=&quot;{Binding EditorFontSize }&quot; &gt;&lt;/Slider&gt;</code></p>
<p>its <code>DataContext</code> is <strong>OptionViewModel</strong>:</p>
<pre><code>public class OptionViewModel: BindableBase
{     
    public int EditorFontSize
    {
        get { return _editorFontSize; }
        set { SetProperty(ref _editorFontSize, value); }
    }
.....
</code></pre>
<p><strong>My problem</strong> is that I have to get the value of the slider in the option window and then I have to modify the FontSize property of my TextBlock with this value. But <strong>I don't know how to send the font size from OptionViewModel to MainViewModel</strong>.</p>
<p>I think that I should use:</p>
<ol>
<li>A shared model</li>
<li>A model in MainWindowViewModel and a ref of this model in OptionViewModel</li>
<li>Other systems like notifications, messages ...</li>
</ol>
<p>I hope that you can help me. It's my first MVVM project and English isn't my main language :S</p>
<p>Thanks</p>