请让我知道我做错了什么
XAMLUserControl
我在哪里使用我的孩子UserControl
的依赖属性
ComboBoxSelectedItem
将更新SelectedEmployee
,
这SelectedEmployee
进一步与我的子控件CardView:uEmployeeCard
ViewModel 属性绑定
<ComboBox Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
Style="{StaticResource UiComboBox}"
ItemsSource="{Binding TB_EMPLOYEEList}"
SelectedItem="{Binding SelectedEmployee,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="ID"
SelectedValue="{Binding CurrentTB_RECIEPT.REFRENCEID}"
ItemTemplate="{StaticResource ComboEmployeeTemplate}"/>
<CardView:uEmployeeCard ViewModel="{Binding Path=SelectedEmployee}"
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
Grid.RowSpan="3" VerticalAlignment="Top"/>
依赖属性代码,uEmployeeCard文件后面的代码:
public uEmployeeCard()
{
InitializeComponent();
this.DataContext = this;
}
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel",
typeof(TB_EMPLOYEE),
typeof(uEmployeeCard), new FrameworkPropertyMetadata
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
[Bindable(true)]
public TB_EMPLOYEE ViewModel
{
get { return (TB_EMPLOYEE)GetValue(ViewModelProperty); } //do NOT modify anything in here
set { SetValue(ViewModelProperty, value); } //...or here
}
uEmployeeCard 的 Xaml 文件(儿童用户控制):
<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal">
<TextBlock Style="{StaticResource UiTextBlock}"
Text="{Binding Path=ViewModel.TITLE}"/>
<TextBlock Style="{StaticResource UiTextBlock}"
Text="{Binding Path=ViewModel.FIRSTNAME}"/>
<TextBlock Style="{StaticResource UiTextBlock}"
Text="{Binding Path=ViewModel.FIRSTNAME}"/>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Vertical" Grid.RowSpan="2">
<TextBlock Style="{StaticResource UiTextBlock}"
Text="{Binding Path=ViewModel.NATNO}"/>
</StackPanel>
我设置了断点来检查依赖属性是否在父用户控件上的 ComboBox 更新时受到影响。但不是...