Suspend Databinding of Controls

前端 未结 6 1345
终归单人心
终归单人心 2021-02-05 13:00

I have a series of controls that are databound to values that change every second or so. From time to time, I need to \"pause\" the controls, so that they do not update their d

6条回答
  •  余生分开走
    2021-02-05 13:17

    If the control you want to suspend has a DataContext (ViewModel) you own, just save it off and null out the DataContext.

    If the control has an inherited DataContext, setting that control's DataContext to null will block the inheritance. Then to resume binding updates, you use the ClearValue method to clear the DataContext DependencyProperty so inheritance kicks in again.

    You can get fancy and use a VisualBrush to take a screen shot of the control you are suspending before clearing its DataContext, so the user doesn't see the control go blank.

提交回复
热议问题