【问题标题】:How to access suggestion listbox of WPF toolkit autocompletebox in viewmodel如何在视图模型中访问 WPF 工具包自动完成框的建议列表框
【发布时间】:2021-07-05 03:10:32
【问题描述】:

在我的项目中,我正在使用来自 dotnetprojects 的 WPF 工具包的自动完成框:

<input:AutoCompleteBox Grid.Row="0" 
                       Height="30" 
                       Width="300"
                       ItemsSource="{Binding Persons}"
                       SelectedItem="{Binding SelectedName, Mode=TwoWay}"
                       ValueMemberPath="DisplayName"
                       ItemTemplate="{StaticResource AutoCompleteBoxItemTemplate}"
                       ItemFilter="{Binding PersonFilter}"
                       Style="{DynamicResource AutoCompleteBoxStyle}"
                       x:Name="AutoCompleteBox">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="TextChanged">
                <i:InvokeCommandAction Command="{Binding TextChanged}"
                                           CommandParameter="{Binding  ElementName=AutoCompleteBox}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</input:AutoCompleteBox>

在 TextChanged 事件中,我将 AutoCompleteBox 作为参数传递给视图模型:

private void TextChangedInternal(object obj)
{
    var box = obj as AutoCompleteBox;
    ...
}

从现在开始,我不知道如何访问弹出窗口中的建议列表框。 我的目的是在建议中突出显示输入的查询。

有人知道如何存档吗?

【问题讨论】:

    标签: c# wpf mvvm autocompletebox


    【解决方案1】:

    您需要将项目模板更改为您可以控制的内容。这意味着您设置了一个 AutoCompleteBox.ItemTemplate。此项目模板将包含找到的每个结果。

    This Tutorial is for silver light 但几乎是您创建自定义控件以突出显示结果中的文本所需的全部内容。完成后,将其添加到 ItemTemplate 的数据模板中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      相关资源
      最近更新 更多