【发布时间】:2014-03-07 11:53:11
【问题描述】:
在应用程序中,我有(简化的)任务:
该应用程序管理有关人员的信息。这些人存储在某个地方(没关系)。 用户可以在列表中添加和删除人员。
人员列表(在程序中经常使用)如下所示:
<UserControl>
...
<StackPanel>
<ListBox
ItemsSource="{Binding Persons}"
SelectedItem="{Binding SelectedPerson}"
SelectionMode="Single"/>
<StackPanel Orientation="Horizontal">
<Button Content="Add Person" Command="{Binding AddPersonCommand}" />
<Button Content="Remove Person" Command="{Binding RemovePersonCommand}" />
</StackPanel>
</StackPanel>
...
</UserControl>
在它的背后是一个我想用于实现的 ViewModel。
现在我希望将这个控件嵌入到另一个控件/窗口中,如下所示:
<personcontrol:PersonControl PersonsCollectionDP="{Binding PersonsFromMainVM}" SelectedPersonDP="{Binding SelectedPersonFromMainVM}" />
(PersonsVM 和 SelectedPersonVM 是嵌入 PersonControl-UC、PersonsDP 和 的 UC/Window 的 VM 中的属性SelectedPersonDP 是 PersonControl-UC 的 DependencyProperty。)
我的问题是将 UC 的属性作为 DependencyProperty 并且(同时)在 UC-ViewModel 中作为属性。
我怎样才能做到这一点?
更新 1
找到this link 正是在此讨论了我的问题但仍未得到解答。也许有人有一个新想法......
【问题讨论】:
标签: wpf mvvm dependency-properties