请让我知道我做错了什么
UserControl
的XAML,我使用我的孩子UserControl
与依赖属性
ComboBox SelectedItem
将更新SelectedEmployee
,
这个qazxsw poi进一步与我的孩子控制qazxsw poi ViewModel Property保持联系
SelectedEmployee
依赖属性代码,uEmployeeCard后面的代码:
CardView:uEmployeeCard
uEmployeeCard的Xaml文件(子用户控件):
<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"/>
我把断点检查是否在父用户控件上从ComboBox更新时依赖属性受到影响。但不是...
您是否已尝试使用以下内容编辑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
}
中的<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>
:
PropertyBinding
你也可以尝试给你的ChildControl
一个名字并绑定你的"Mode=TwoWay, UpdateSourceTrigger=PropertyChanged"
:
ComboBox