我需要从组合框中获取选定的项目作为命令参数。 但是第一次在命令参数中接收到作为旧值的所选项目。
XAML:
<DataTemplate x:Uid="DataTemplate_2">
<control:ComboBox x:Uid="ComboBoxType"
x:Name="AstmComboBox"
HorizontalAlignment="Stretch"
Height="20"
FlowDirection="LeftToRight"
HorizontalContentAlignment="Right"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type control:UserControl}}, Path=DataContext.InclusionTypes}"
SelectedItem="{Binding Path=ClassName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding DataContext.IsReclassificationAllowed, RelativeSource={RelativeSource AncestorType=control:DataGrid}}"
Width="Auto">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type control:UserControl}},Path=DataContext.ClassChangedCommand, Mode=OneWay}"
CommandParameter="{Binding ElementName=AstmComboBox, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</control:ComboBox>
</DataTemplate>
在viewmodel中,我具有中继命令
public RelayCommand ClassChangedCommand
{
get
{
return _classChangedCommand ?? (_classChangedCommand = new RelayCommand(ClassChanged));
}
}
private void ClassChanged(object obj)
{
{
SetSelectedItemsType(obj as string);
}
}
这是第一次收到的obj具有组合框项目的旧值。