[英]WPF combobox custom control text search functionality
I am having a cutom combo box control in my WPF MVVM application and I am trying to enable serach in the box. 我在WPF MVVM应用程序中有一个组合框控件,并且正在尝试在框中启用Serach。 This means whenever a user will type anything on the cmb box it will display those pertainig records.
这意味着每当用户在cmb框中键入任何内容时,它将显示那些相关记录。
I am using below code but unable to see this working. 我正在使用下面的代码,但看不到此工作。
<ComboBox x:Class="ABC.Selector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:ABC.ViewModels"
TextSearch.TextPath ="{Binding Name}" IsEditable="True">
>
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type vm:MyViewModel}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Margin="0 0 5 0"/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
This functionality works with below code : 此功能适用于以下代码:
<ComboBox Grid.Column="3" Grid.Row="1" HorizontalAlignment="Stretch" Name="cmb"
VerticalAlignment="Stretch" Height="Auto" Grid.ColumnSpan="9"
ItemsSource="{Binding Details}"
SelectedItem="{Binding Selected, Mode=TwoWay}">
<TextSearch.TextPath>Name</TextSearch.TextPath>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock DataContext="{Binding}">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} - {1}">
<Binding Path="Name" />
<Binding Path="LongName" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Any idea how to enable this in first code block ? 知道如何在第一个代码块中启用它吗?
TextPath
does not expect a binding to the actual value; TextPath
不希望绑定到实际值。 it expects the name of the property to search. 它希望搜索属性的名称 。 You should set
TextSearch.TextPath="Name"
. 您应该设置
TextSearch.TextPath="Name"
。
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="vendorCombo" ItemsSource="{Binding DataContext.VendorMasterSource, RelativeSource={RelativeSource AncestorType=Page}}"
SelectedValue="{Binding VendorNo,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectedValuePath="VENDOR_MASTER_ID"
behaviour:ComboBoxSeletionChangedBehaviour.ComboBoxSeletionChangedCommand=
"{Binding DataContext.SelectionChangedCommand, RelativeSource={RelativeSource AncestorType=Page}}" TextSearch.TextPath="NAME" IsTextSearchEnabled="True" IsEditable="True" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=NUMBER}"/>
<TextBlock Text=" - "/>
<TextBlock Text="{Binding Path=NAME}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.