WPF ComboBox
项目中的问题:
XAML:
<ComboBox x:Name="cboSelectSeries" Width="100" Height="25" Grid.Row="3"
Grid.Column="3" SelectedIndex="0"
ItemsSource="{Binding}" SelectedValuePath="SeriesNumber"
DisplayMemberPath="NId" />
XAML.cs
internal List<NPIS.PortableObject.NPIS> NCollection;
..
NCollection=getdata();
cboSelectSeries.DataContext = NCollection;
输出:
项目为“NPIS.PortableObject.NPIS”
答案 0 :(得分:0)
我怀疑它在课程NId
中找不到属性路径NPIS
。确保您在基础类中有公开公开属性。路径名称区分大小写,请确保路径名称和属性名称正确。
public int NId { get; set; }
答案 1 :(得分:0)
我尝试了以下代码,但确实有效。
public partial class MainWindow : Window
{
public List<PortableObject> NCollection;
public MainWindow()
{
InitializeComponent();
NCollection = getdata();
cboSelectSeries.DataContext = NCollection;
}
private List<PortableObject> getdata()
{
return new List<PortableObject>
{
new PortableObject
{
SeriesNumber = 001,
NId = 10,
},
new PortableObject
{
SeriesNumber = 002,
NId = 20,
},
new PortableObject
{
SeriesNumber = 003,
NId = 30,
},
};
}
}
public class PortableObject
{
public int SeriesNumber { get; set; }
public int NId { get; set; }
}