首页 > 解决方案 > 组合框从列表中添加项目

问题描述

我有一个组合框,我想将列表填充到其中。目前,我可以填充列表,但无法显示它的字符串。

这是从组合框中显示的输出:

solution_name.folder_name.class_name

这是我的用户 C# 代码:

userRoleList.Add(new User()
{
    UserRole = reader[1].ToString()
});

这是我的 xaml 代码:

<ComboBox x:Name="cbUserRole" FlowDirection="LeftToRight" FontSize="16" Foreground="MidnightBlue" HorizontalAlignment="Stretch" VerticalAlignment="Center" ItemsSource="{Binding}"/>

这是我的 viewuser c# 代码:

var userRolesList = new User().getUserRoles();
ComboBox cbUserRole = (ComboBox)GetChildren(userDataGrid).First(x => x.Name == "cbUserRole");
cbUserRole.ItemsSource = userRolesList;

如何在组合框中显示字符串?

标签: c#wpf

解决方案


推荐阅读