Real-time binding in WPF

Very simple, how can I make the binding more responsive. That is, the change of interface is closer to when the view model changes in the background.

I have a timer progress bar that is incredibly nervous. And I have a touch keyboard that updates the field like a clock (exaggeration) after a key is pressed.

+3
source share
2 answers

The problem is the priority of the Dispatcher queue (see this ). Even if you need to respond faster to changes in the ViewModel (for example, manually updating controls), the rendering itself is done with lower priority. Thus, I believe that there will be no noticeable difference for you, because the user will not see it after the next rendering.

EDIT: In general, the user interface in WPF, even when performing data binding, is very responsive. However, there are several reasons why this can be slow (see the application using the WPF performance toolkit ):

  • ( ) /. , , 400 , . , . , .
  • ( ) . , , , . (BackgroundWorker, ThreadPool thread,...).
  • . / / ..
+2

, , , :

(1). :

<TextBlock Text="{Binding ViewModelTextProperty, IsAsync=True}"/>

, ViewModelTextProperty .

(2). PriorityBinding - , -, :

<TextBlock>
   <TextBlock.Text>
      <PriorityBinding>
          <Binding Path="ViewModelTextProperty" IsAsync="True"/>
          <Binding Path="FastViewModelTextProperty" IsAsync="True"/>
      </PriorityBinding>
   </TextBlock.Text>
</TextBlock>

buttom. FastViewModelTextProperty, ViewModelTextProperty , .

(3). , , ( , ..). , , UI ( ) Dispatcher:

private void OnAsyncOperationCompleted()
{
   Application.Current.Dispatcher.BeginInvoke(new Action(() => {
      // Update the UI
   }));
}
+4

Source: https://habr.com/ru/post/1789795/


All Articles