【发布时间】:2010-04-14 13:23:48
【问题描述】:
这就是我想要做的:
- 我正在写一个
UserControl,我想被其他开发者使用。 -
我希望最终用户能够使用依赖属性来使用我的控件。
<lib:ControlView ControlsText={Binding Path=UsersOwnViewModelText} /> 我正在使用 MVVM 模式。
-
我正在使用
<DataTemplates>将我的 ViewModel 绑定到他们的 View 上<DataTemplate DataType="{x:Type local:ControlViewModel}"> <local:ControlView /> </DataTemplate>
所以我有两个问题:
如果在 XAML 中使用 UserControl,那么当控件的
Loaded事件触发而不是使用<DataTemplate>方法时,UserControl 必须将 ViewModel 设置为其DataContext,我的想法是否正确?如何允许用户将数据绑定到我的控件的依赖属性,同时仍将数据绑定到我的 ViewModel?
【问题讨论】:
-
当我准备这个问题时,我在这里看到了。谢谢你的提问 :)
标签: wpf user-controls mvvm dependency-properties