我正在将来自数据库的数据绑定到 ListBoxItem
,以下是代码:
public void load_users()
{
RST_DBDataContext conn = new RST_DBDataContext();
List<TblUser> users = (from s in conn.TblUsers
select s).ToList();
Login_Names.ItemsSource = users;
}
在XAML中,有以下代码:
<ListBox Name="Login_Names"
ItemsSource="{Binding Path=UserName}"
HorizontalAlignment="Left"
Height="337" Margin="10,47,0,0"
Padding="0,0,0,0" VerticalAlignment="Top" Width="156">
但它并没有起作用,它显示了表名,但我需要看到来自表中的用户名,表中有一个称为UserName的列。
提前感谢。