Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将listview中的combobox绑定到集合_C#_Wpf_Xaml_Listview_Combobox - Fatal编程技术网

C# 将listview中的combobox绑定到集合

C# 将listview中的combobox绑定到集合,c#,wpf,xaml,listview,combobox,C#,Wpf,Xaml,Listview,Combobox,这是我的对象模型 private class ShellItem { public string Name { get; set; } public string Command { get; set; } public List<ShellMenu> ShellMenus { get; private set; } public ShellItem() { ShellMenus = new List<ShellMe

这是我的对象模型

private class ShellItem
{
    public string Name { get; set; }

    public string Command { get; set; }

    public List<ShellMenu> ShellMenus { get; private set; }

    public ShellItem()
    {
        ShellMenus = new List<ShellMenu>();
    }
}


public class ShellMenu
{
    public string ExtName;

    public string KeyName;

    public string FileType;

    public string MenuName { get; set; }

    public string Command { get; set; }

}
私有类ShellItem
{
公共字符串名称{get;set;}
公共字符串命令{get;set;}
公共列表外壳菜单{get;private set;}
公共物品(
{
ShellMenus=新列表();
}
}
公共类外壳菜单
{
公共字符串ExtName;
公共字符串键名;
公共字符串文件类型;
公共字符串菜单名{get;set;}
公共字符串命令{get;set;}
}
这是我的xaml

<ListView Name="listViewRightClick" HorizontalAlignment="Stretch" Height="Auto" Margin="10,10,26.667,107.667" VerticalAlignment="Stretch" Width="Auto">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="200" Header="Name" DisplayMemberBinding="{Binding Name}"/>
                    <GridViewColumn Width="600" Header="Command" DisplayMemberBinding="{Binding Command}"/>
                    <GridViewColumn Width="200" Header="FileTypes">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding ShellMenus}"
                                          SelectedValue="{Binding MenuName}"
                                          Margin="-6, 0, -6, 0"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>

我的问题不是显示shellMenu的MenuName,而是在combobox的每个项目上显示MyNamespace.shellMenu。

只是关于选择,用于显示

DisplayMemberPath=“MenuName”
仅用于选择,用于显示

DisplayMemberPath=“MenuName”

您需要在
组合框中指定
DisplayMemberPath

<ComboBox 
    ItemsSource="{Binding ShellMenus}"
    SelectedValue="{Binding MenuName}"
    DisplayMemberPath="MenuName"
    Margin="-6, 0, -6, 0"/> 

您需要在
组合框中指定
DisplayMemberPath

<ComboBox 
    ItemsSource="{Binding ShellMenus}"
    SelectedValue="{Binding MenuName}"
    DisplayMemberPath="MenuName"
    Margin="-6, 0, -6, 0"/> 


@RaviPatel:您指定了绑定吗?这只是一个成员名。它现在可以工作了,但为什么我们不把它称为DisplayMemberPath=“Binding Menuame”。这是我使用wpf的第一天。@RaviPatel:因为这只是属性的实现方式,它甚至在名称中说它是一个成员的路径,如果您不知道属性是如何工作的,请阅读文档。是否可以在组合框中添加一个默认选择的默认值?@RaviPatel:这是另一个问题,可能已经回答过了。请四处看看,不要问我。@RaviPatel:您指定了绑定吗?这只是一个成员名。它现在可以工作了,但为什么我们不把它称为DisplayMemberPath=“Binding Menuame”。这是我使用wpf的第一天。@RaviPatel:因为这只是属性的实现方式,它甚至在名称中说它是一个成员的路径,如果您不知道属性是如何工作的,请阅读文档。是否可以在组合框中添加一个默认选择的默认值?@RaviPatel:这是另一个问题,可能已经回答过了。环顾四周,而不是问我。我认为在这个链接中你可以找到你的答案:我认为在这个链接中你可以找到你的答案: