Note that there are some explanatory texts on larger screens.

plurals
  1. POMVVM updating Label
    primarykey
    data
    text
    <p>I know this is a frequently asked question, but I'm trying to solve it at least a week now... Read so many Threads, downloaded millions of different MVVM-Pattern-Examples and so on...</p> <p>I just want to update a stupid label in my MVVM modelview first approach:</p> <pre><code> void StartUpProcess_DoWork(object sender, DoWorkEventArgs e) { SplashWindow splash = new SplashWindow(); var ViewModel_Splash = new VM_SplashWindow(); splash.DataContext = ViewModel_Splash; splash.Topmost = true; splash.Show(); ViewModel_Splash.DoWork(); } </code></pre> <p>The complete ViewModel: </p> <pre><code>public class VM_SplashWindow:VM_Base { #region Properties private string _TextMessage; public string TextMessage { get { return _TextMessage; } set { if(_TextMessage != value) { _TextMessage = value; base.OnPropertyChanged("TextMessage"); } } } #endregion #region Methods public void DoWork() { this.TextMessage = "Initialize"; for(int aa = 0; aa &lt; 1000; aa++) { this.TextMessage = "Load Modul: " + aa.ToString(); Thread.Sleep(5); } this.TextMessage = "Done"; Thread.Sleep(1000); } #endregion } </code></pre> <p>A small piece from the base:</p> <pre><code>public abstract class VM_Base:INotifyPropertyChanged, IDisposable { #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { var e = new PropertyChangedEventArgs(propertyName); handler(this, e); } } #endregion } </code></pre> <p>And finally the view:</p> <pre><code>&lt;Label Height="28" Margin="19,0,17,15" Name="label2" VerticalAlignment="Bottom" Content="{Binding Path=TextMessage}" Foreground="White" /&gt; </code></pre> <p>If I set a initial value for the TextMessage Property in the constructor of my viewmodel, this initial value will be shown after the splash.Show() command. </p> <p>Setting the TextMessage Property in the DoWork-Method raises the onPropertyChangedEvent but unfortunately it will not update the label in the window. I don't know what I should do... I'm really looking forward for help. Many thanks in advance! </p> <p>maybe I should mention that the StartUpProcess_DoWork is running in a own STAThread</p> <p>kind regards, flo</p>
    singulars
    1. This table or related slice is empty.
    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. 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