相关疑难解决方法(0)

如何使用带有可编辑组合框的 EventToCommand 将 TextBoxBase.TextChanged 与命令绑定?

我有一个可编辑的组合框。

<ComboBox IsEditable="True">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <cmd:EventToCommand Command="{Binding CritereChangedCommand, Mode=OneWay}"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="TextBoxBase.TextChanged">
            <cmd:EventToCommand Command="{Binding CritereChangedCommand, Mode=OneWay}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

我使用 GalaSoft.MvvmLight.Command.EventToCommand 绑定 SelectionChanged 事件。
我还想绑定 TextChanged 事件,但有点棘手:此事件只能通过 ComboBox TextBoxBase 属性访问,并且我找不到绑定此事件的正确方法。
您可以看到我不成功的尝试之一:SelectionChanged 绑定工作正常,但 TextChanged 绑定不行。

我也尝试过这个语法:

<ComboBox IsEditable="True">
    <TextBoxBase>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="TextChanged">
                <cmd:EventToCommand Command="{Binding CritereChangedCommand, Mode=OneWay}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </TextBoxBase>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <cmd:EventToCommand Command="{Binding CritereChangedCommand, Mode=OneWay}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

但这甚至无法编译。我在 TextBoxBase 标记上收到错误“可以预期实例化的类型”。

任何想法 ?

wpf xaml combobox mvvm-light eventtocommand

3
推荐指数
1
解决办法
4150
查看次数

标签 统计

combobox ×1

eventtocommand ×1

mvvm-light ×1

wpf ×1

xaml ×1