Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF UI not updating after incoming WCF message
    primarykey
    data
    text
    <p>I have an MVVM app, where my ViewModel <code>PingerViewModel</code> processes incoming WCF <code>Ping()</code> messages. Processing such a message happens on a thread of <code>Scheduler.Default</code>'s thread pool. Semantically, incoming WCF messages change a bound property <code>CanPing</code> and raise the PropertyChanged event for said property.</p> <p><strong>But my UI is not updating</strong> until it receives some UI event, e.g. focusing/clicking the window, etc.<br/> <strong>How do I make it update as soon as the event is fired?</strong></p> <p>I have tried raising the PropertyChanged event...</p> <ul> <li>on the Application's Dispatcher, </li> <li>using a SynchronizationContext</li> </ul> <p>without any luck.</p> <p>I also verified that the bound property is indeed set to the proper value, and that there is indeed a listener consuming my PropertyChanged event.</p> <p>Here's some code (<a href="https://github.com/derabbink/DistrExTest" rel="nofollow">full code on github</a>):<br/> part of my view's MainWindow.xaml:<br/> It might be worth noting that the bound <code>Command</code> does not actually play a role in producing the incoming WCF message.</p> <pre><code>&lt;Button Content="Ping" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="PingBtn" VerticalAlignment="Top" Width="75" AutomationProperties.AutomationId="Ping" IsEnabled="{Binding CanPing}" Command="{Binding PingCommand}" /&gt; </code></pre> <p>part of my views MainWindow.xaml.cs</p> <pre><code>public MainWindow() { DataContext = new PingerViewModel(); InitializeComponent(); } </code></pre> <p>part of my ViewModel</p> <pre><code>public class PingerViewModel : INotifyPropertyChanged public PingerViewModel() { Pinger = new Pinger(true); PingCommand = new PingerPingCommand(this); //... } public bool CanPing { get { if (Pinger == null) return false; return Pinger.CanPing; } } public void Ping() { _pingClient.Channel.Ping(); Pinger.CanPing = false; OnPropertyChanged("CanPing"); } protected virtual void OnPong(PongEventArgs e) { Pinger.CanPing = true; OnPropertyChanged("CanPing"); } public Pinger Pinger { get; private set; } public ICommand PingCommand { get; private set; } //... } </code></pre>
    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.
 

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