如何将丢失的焦点绑定到ViewModel中的命令

时间:2019-01-31 16:16:29

标签: wpf xaml mvvm

<ComboBox x:Name="PrimaryCountyFIPS" Grid.Row="3" Grid.Column="3" Margin="3"
                        IsSynchronizedWithCurrentItem="False"
                        IsEditable="True"
                        LostFocus="{Binding LostFocusCommand }"
                        ItemContainerStyle ="{StaticResource ComboBoxItemStyle}"
                        IsEnabled="{Binding IsChecked, ElementName=IncludePrimZipCodeCheckBox}"
                        ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type viewmodel:GeocoderDataCleanerViewModel}, AncestorLevel=1}, Path=DestinationColsDictionary}" DisplayMemberPath="Value" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type viewmodel:GeocoderDataCleanerViewModel}, AncestorLevel=1}, Path=PrimaryCountyFIPSField, Mode=OneWay}">
        </ComboBox>
  

我有一个ComboBox,我想将其丢失的焦点事件绑定到ViewModel中的命令。当我尝试绑定它时,出现一个错误,提示“ LostFocus不是一种方法”,我该如何将其绑定到该Command,甚至有可能?

1 个答案:

答案 0 :(得分:0)

我想这就是您要寻找的东西

    <ComboBox>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="LostFocus">
                <i:InvokeCommandAction Command="{Binding Path=DoSomethingCommand}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ComboBox>