WPF组合框不可编辑

时间:2015-12-08 09:45:21

标签: c# wpf combobox

我有一个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);
    }
}

1 个答案:

答案 0 :(得分:0)

你在寻找像这样的东西

<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>