简体   繁体   中英

How to Create Mandatory Dependency Property in XAML WPF

I am creating User Control. I created three dependency properties which the user should bind to a viewmodel in XAML.

Is there something I can do so if developer does not bind the property? Ideally, the project would not compile successfully.

This is impossible. Bindings are only checked at run-time, not at compile-time. The reason for this is that the compiler cannot determine what datacontext you wish to set for a view while the application is running since you can always change the datacontext.

If you're interested you can look up the MVVM design pattern to learn more about the reason why the model and view are seperated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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