Raj*_*aja 2 c# wpf user-controls dependency-properties mvvm
我尝试使用MVVM在WPF中创建一个简单的UserControl.现在我需要为UserControl创建一个依赖项属性,所以我尝试在UserControlViewModel中创建依赖项属性(我不想在代码隐藏中).
为了在UserControlViewModel中创建依赖项属性,我需要从DependencyObject继承.在UserControlViewModel中继承DependencyObject是一个好习惯吗?也就是说,它是一个跟踪MVVM设计UserControl的好方法吗?
如果您创建了一个自定义控件,其中包含您希望它们可绑定的属性(例如,以下代码),则无法使用INotifyPropertyChanged,必须使用DependencyObject.
<MyUserControl MyDependencyProperty="{Binding PropertyPath}" />
Run Code Online (Sandbox Code Playgroud)
但在使用时DependencyObjects你应该记住:
DependencyObjects 未标记为可序列化. DependencyObject类用于覆盖和密封件均Equals()和
GetHashCode()方法.A DependencyObject具有线程关联性 - 只能在创建它的线程上访问它.
| 归档时间: |
|
| 查看次数: |
2222 次 |
| 最近记录: |