WPF组合框是可编辑的,不可编辑

本文关键字:编辑 组合 WPF | 更新日期: 2023-09-27 18:26:08

我有一个WPF表单,其中有一个包含文件夹中项目的组合框。我想使组合框可编辑。这样,当我键入一些单词时,它应该打开带有匹配视频名称的组合框。

WPF

<ComboBox x:Name="data" IsEditable="True" FontFamily="verdana" Text=""  FontSize="28" HorizontalAlignment="Left" Height="81" Margin="29,214,0,0" VerticalAlignment="Top" Width="326" SelectionChanged="data_SelectionChanged"/>
<ItemsControl Name="VideoList" ItemsSource="{Binding VideoList}" Margin="434,134,0,10" HorizontalAlignment="Left" Width="733">

.cs

public TextToSignWindow() //constructor
{
    InitializeComponent();
    var rootFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    var root = rootFolder + @"'Videos'";
    string localPath = new Uri(root).LocalPath;
    PopulateListBox(data, localPath, " * .wmv ");
}
private void PopulateListBox(ComboBox cmb, string Folder, string FileType)
{
    DirectoryInfo dinfo = new DirectoryInfo(Folder);
    FileInfo[] Files = dinfo.GetFiles(FileType);
    foreach(FileInfo file in Files)
    {
        cmb.Items.Add(file.Name);
    }
}

WPF组合框是可编辑的,不可编辑

你在寻找类似的东西吗

<ComboBox Grid.Column="3" Grid.Row="15" Height="Auto" HorizontalAlignment="Stretch" 
                Name="cmbName" VerticalAlignment="Stretch"
                SelectedItem="{Binding Name, Mode=TwoWay}"
                ItemsSource="{Binding GetAllName}">
            <TextSearch.TextPath>FirstName</TextSearch.TextPath>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock DataContext="{Binding}">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0} - {1}">
                                <Binding Path="FirstName" />
                                <Binding Path="LastName" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>