C# WPF组合框自定义控件文本搜索功能
我在我的WPF MVVM应用程序中有一个cutom组合框控件,我正在尝试在框中启用serach。这意味着每当用户在cmb框中键入任何内容时,它都会显示这些相关记录 我正在使用下面的代码,但无法看到此工作C# WPF组合框自定义控件文本搜索功能,c#,wpf,mvvm,wpf-controls,C#,Wpf,Mvvm,Wpf Controls,我在我的WPF MVVM应用程序中有一个cutom组合框控件,我正在尝试在框中启用serach。这意味着每当用户在cmb框中键入任何内容时,它都会显示这些相关记录 我正在使用下面的代码,但无法看到此工作 <ComboBox x:Class="ABC.Selector" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.micr
<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>
>
此功能适用于以下代码:
<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>
名称
知道如何在第一个代码块中启用此功能吗?
TextPath
不希望绑定到实际值;它需要搜索属性的名称。您应该设置TextSearch.TextPath=“Name”
您有什么问题吗?有。我想在我的第一个代码块中启用此功能。我执行了TextSearch.TextPath=“Name”,但它不起作用。您的详细信息
收藏中的每个项目都有一个名称
属性,是吗?这就是您要搜索的属性?如果是这样的话,这应该行得通。理想情况下,这应该行得通,但根本行不通。我不知道我遗漏了什么。你能解释一下你的答案吗?@phuzi当然可以,用这三个组合框作为搜索框TextSearch.TextPath=“NAME”IsTextSearchEnabled=“True”IsEditable=“True”
这将为您启用搜索功能!。
<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>