Note that there are some explanatory texts on larger screens.

plurals
  1. POWpf Xaml view not updating
    text
    copied!<p>I have a splash screen that is supposed to show the loading process as the program starts up. I cannot get the text in the label to update as components are loaded.</p> <p>From the main start-up program.cs I call the run() method in the splash screen controller.</p> <pre><code>startUpSplash.Run(); </code></pre> <p>Here is the controller. This shows the splash screen with the label "Initializing..."</p> <pre><code> public class StartUpSplashController { public StartUpSplashViewModel ViewModel { get; set; } private StartUpSplashView starUpSplashWindow = new StartUpSplashView(); private delegate void UIDelegate(); public void Run() { InitializeViewModel(); ViewModel.StatusMessage = "Initializing..."; starUpSplashWindow.DataContext = ViewModel; starUpSplashWindow.Show(); } public void UpdateStatus(string statusMessage) { starUpSplashWindow.Dispatcher.Invoke(new UIDelegate(delegate { ViewModel.StatusMessage = statusMessage; })); //ViewModel.StatusMessage = statusMessage; } public void End() { starUpSplashWindow.Close(); starUpSplashWindow.InvalidateVisual(); } private void InitializeViewModel() { ViewModel = new StartUpSplashViewModel(starUpSplashWindow); ViewModel.Controller = this; } } </code></pre> <p>Then from the main program.cs as different things are happening I call this UpdateStatus method also in the splash controller. This is meant to update the label to show all the different thing that are happening.</p> <p>This is the Xaml for the lbl that is supposed to be getting updated.</p> <pre><code> &lt;Label Content="{Binding Path=StatusMessage, Mode=TwoWay, UpdateSourceTrigger= PropertyChanged}" /&gt; </code></pre> <p>The label is not updating when the UpdateStatus method is called. One strange thing I noticed was that if I did a </p> <pre><code>startupSplash.UpdateStatus("something"); </code></pre> <p>and then</p> <pre><code>Messagebox.show("something"); </code></pre> <p>The splash screen shows the updated label after the messagebox has popped up.</p> <p>Any help with this would be appreciated.</p> <p>UPDATE 2: Here is the View Model</p> <pre><code>public class StartUpSplashViewModel : ViewModel&lt;IView&gt; { [ImportingConstructor] public StartUpSplashViewModel(StartUpSplashView view) : base(view) { } public StartUpSplashController Controller { get; set; } private string _statusMessage; public string StatusMessage { get { return _statusMessage; } set { if (_statusMessage == value) return; _statusMessage = value; this.RaisePropertyChanged(s =&gt; s.StatusMessage); } } } </code></pre>
 

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