【发布时间】:2011-02-21 08:31:26
【问题描述】:
我将一个数据表绑定到一个组合框并在 itemTemplate 中定义了一个 dataTemplate。我可以在组合框下拉列表中看到所需的值,我在 selectedItem 中看到的是System.Data.DataRowView 这是我的代码:
<ComboBox Margin="128,139,123,0" Name="cmbEmail" Height="23" VerticalAlignment="Top" TabIndex="1" ToolTip="enter the email you signed up with here" IsEditable="True" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=username}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
后面的代码是这样的:
if (con != null)
{
con.Open();
//users table has columns id | username | pass
SQLiteCommand cmd = new SQLiteCommand("select * from users", con);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
userdt = new DataTable("users");
da.Fill(userdt);
cmbEmail.DataContext = userdt;
}
我一直在寻找像 SelectedValueTemplate 或 SelectedItemTemplate 这样的东西来做同样类型的数据模板,但我没有找到。
我想问一下是我做错了什么还是组合框绑定的已知问题?
如果我的代码有问题,请指出正确的方向。
感谢您阅读本文
【问题讨论】:
标签: c# wpf data-binding wpf-controls binding