【问题标题】:How to bind ListView inside a RadRibbonDropDownButton in a grid cell template?如何在网格单元格模板中的 RadRibbonDropDownButton 内绑定 ListView?
【发布时间】:2016-08-11 15:46:02
【问题描述】:

我有一个 rad 网格视图,它将它的 itemssource 绑定到一个“员工”列表。 “员工”实体有一个“角色”属性列表。如何将此“角色”绑定到ListView,如下所示。

例如:在第二列中,RadComboBox 正确绑定。在第三列中,RadRibbonDropDownButton 没有正确绑定。 我如何将 RolesList 绑定到 ListViewRadRibbonDropDownButton

请帮忙。

class Employee
{
    public string Name {get; set;}
    public List<Role> RolesList {get; set;}
}
class Role
{
    public int RoleId {get; set;}
    public string RoleName {get; set;}
    public string RoleCategory {get; set;}
}
<tk:RadGridView ItemsSource="{Binding Path=EmployeeList,Mode=TwoWay}" AutoGenerateColumns="False">
    <tk:RadGridView.Columns>
        <tk:GridViewDataColumn Header="Employee Name" DataMemberBinding="{Binding Name}" IsReadOnly="True"/>
        <tk:GridViewDataColumn Header="Roles" Width="410">
            <tk:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <!--this binds properly-->
                    <tk:RadComboBox ItemsSource="{Binding RolesList}" DisplayMemberPath="RoleName" SelectedValuePath="RoleId" />
                </DataTemplate>
            </tk:GridViewDataColumn.CellTemplate>
        </tk:GridViewDataColumn>
        <tk:GridViewDataColumn Header="Roles" Width="410">
            <tk:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <tk:RadRibbonDropDownButton>
                        <tk:RadRibbonDropDownButton.DropDownContent>
                            <ListView ItemsSource="{Binding RolesList}">
                                <ListView.View>
                                    <GridView AllowsColumnReorder="False">
                                        <GridViewColumn DisplayMemberBinding="{Binding RoleName}" Header="Role Name" Width="75" ></GridViewColumn>
                                        <GridViewColumn DisplayMemberBinding="{Binding RoleCategory}" Header="Role Category" Width="175" ></GridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </tk:RadRibbonDropDownButton.DropDownContent>
                    </tk:RadRibbonDropDownButton>
                </DataTemplate>
            </tk:GridViewDataColumn.CellTemplate>
        </tk:GridViewDataColumn>
    </tk:RadGridView.Columns>
</tk:RadGridView>

【问题讨论】:

  • 呃,你为什么在 Gridview 中使用 Ribbon-Element?
  • 我希望下拉菜单是一个网格

标签: c# .net wpf radgridview


【解决方案1】:

添加 DataContext={Binding} 修复了绑定问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    相关资源
    最近更新 更多