简体   繁体   English

WPF MVVM-初始化和绑定(Get方法)

[英]WPF MVVM - Initialization and Binding (Get method)

During the initialization of a View and it's respective ViewModel the WPF calls all the 'Get' methods from the Properties that have a Binding with a View Component. 在View及其各自的ViewModel初始化期间,WPF从具有与View Component绑定的Properties中调用所有的“ Get”方法。

Can I prevent the WPF from calling the Get methods during the initialization? 我可以防止WPF在初始化期间调用Get方法吗?

No, because thats how the bindings initialize (unless they are OneWayToSource , but if they were I doubt you would think this was a problem)! 不,因为那是绑定初始化的方式(除非它们是OneWayToSource ,但是如果我怀疑它们,您会认为这是个问题)! However, you can just not set DataContext until later. 但是,直到稍后您才能设置DataContext Setting that should fire DataContextChanged and cause your bindings to update. 设置, 应该DataContextChanged ,使你的绑定更新。

In all reality though, why do you want to do this? 但实际上,为什么要这样做? PropertyChanged is designed for handling the changes that occur after initialization. PropertyChanged设计用于处理初始化后发生的更改。

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

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