WPF Combobox Filter 사용법이 궁금합니다.

아하!
일단 콤보박스의 에디트 기능으로 구현해서 테스트해봤는데
차이점이라고 한다면 DataGrid의 Combox를 사용하지 않았습니다!

한번 비교해서 봐보세요!
XAML

<Window
    x:Class="ComboboxFilterTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:ComboboxFilterTest"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Window.Resources>
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="Width" Value="170" />
            <Setter Property="Height" Value="21" />
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
        <ComboBox
            x:Name="bizColumn"
            Grid.Column="2"
            DisplayMemberPath="Display"
            IsEditable="True"
            ItemsSource="{Binding BizList}"
            KeyUp="bizColumn_KeyUp" />
    </Grid>
</Window>

behind

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent ();
        this.DataContext = new MainViewModel ();
    }

    private bool FilterPredicate(object obj)
    {
        string sValue = string.Empty;

        if (obj is string)
            sValue = obj.ToString ();
        else if (obj is ComboBoxItem)
            sValue = (obj as ComboBoxItem).Content.ToString ();
        else
        {
            System.Reflection.PropertyInfo info = obj.GetType ().GetProperty (bizColumn.DisplayMemberPath);
            if (info != null)
            {
                object oValue = info.GetValue (obj, null);
                if (oValue != null)
                {
                    sValue = oValue.ToString ();
                }
            }

        }

        if (!string.IsNullOrEmpty (sValue) && sValue.Contains (tb.Text))
            return true;
        else
            return false;

    }
    TextBox tb;
    private void bizColumn_KeyUp(object sender, KeyEventArgs e)
    {
        ComboBox comboBox = sender as ComboBox;
        comboBox.Items.Filter -= this.FilterPredicate; //NotSupport 에러
        tb = comboBox.Template.FindName ("PART_EditableTextBox", comboBox) as TextBox;



        if (e.Key == Key.Enter || e.Key == Key.Tab || e.Key == Key.Return)
        {
            return;

        }
        else
        {
            comboBox.IsDropDownOpen = true;
            comboBox.Items.Filter += this.FilterPredicate; //NotSupport 에러
        }


    }
}

viewmodel

public class bizModel
{
    public string Display { get; set; }
    public string Value { get; set; }
}
public partial class MainViewModel :ObservableObject
{
    [ObservableProperty] List<bizModel> bizList;
    public MainViewModel()
    {
        BizList = new ();
        BizList.Add (new bizModel { Display = "하하", Value = "12345" });
        BizList.Add (new bizModel { Display = "호호", Value = "67890" });
        BizList.Add (new bizModel { Display = "카캬", Value = "AAAAA" });
        BizList.Add (new bizModel { Display = "푸푸", Value = "BBBBB" });
        BizList.Add (new bizModel { Display = "소소", Value = "CCCCC" });
    }
}

Screenshot 2023-12-19 at 10.46.40

4개의 좋아요