简体   繁体   English

跟踪用户控件的datacontext是否会导致属性更改事件触发?

[英]will chaging the datacontext of a user control cause the property changed events to fire?

I have a user control on which I am planning to switch out the datacontext on certain events. 我有一个用户控件,我计划在某些事件上关闭数据上下文。 The control has several text boxes and a list view, etc.. etc... The question is will simply saying view.DataContext = new viewModel(); 该控件有几个文本框和一个列表视图,等等。等等...问题将简单地讲为view.DataContext = new viewModel();。 be enough? 足够? or will have have to tell all of the property changed events to fire? 还是必须告诉所有财产变更事件才能起火?

Thanks 谢谢

是的,如果UI控件后面的DataContext发生更改,WPF将自动更新UI绑定。

Yes. 是。 However - you need to consider the scope of the data context change for performance reasons. 但是,出于性能原因,您需要考虑数据上下文更改的范围。 If your context change affects the entire form - it could slow down the application. 如果您的上下文更改影响整个表单,则可能会使应用程序变慢。 Use the profiling tools for WPF to see the affects of this. 使用WPF的配置工具可以查看其影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM