如何将丢失的焦点绑定到视图模型中的命令


<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>

有一个组合框,我想将其失去焦点的事件绑定到我在其 ViewModel 中的命令。当我尝试绑定它时,我收到一个错误,说"LostFocus 不是一种方法"我将如何将其绑定到该命令,或者甚至可能吗?

我想这就是你要找的:

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

最新更新