我将具有平台的类设备作为属性之一:
public partial class DevicesCollection : ObservableCollection<Device>
{
public DevicesCollection() : base()
{ }
}
public partial class Device : INotifyPropertyChanged
{
private string hostIP;
private string password;
private int platform;
private string status = "";
private int loop = 1;
public Device() { }
public Device(string ip, string pswd, int tp)
{
HostIP = ip;
Password = pswd;
Platform = tp;
Status = "Disconnected";
Loop = 1;
}
以及我有平台类:
public partial class PlatformsCollection : ObservableCollection<Platform>
{
public PlatformsCollection()
: base()
{
Add(new Platform(1, "iOS"));
Add(new Platform(2, "Android"));
Add(new Platform(3, "Windows"));
Add(new Platform(4, "Blackberry"));
}
}
public partial class Platform : INotifyPropertyChanged
{
private string platformName;
private int platformId;
public Platform(int id, string name)
{
PlatformName = name;
PlatformId = id;
}
....
我有一个DataGrid
绑定到 Devices 类的列,其中一列是ComboBox
我试图绑定到 Platform 类的 Platform:
<DataGridComboBoxColumn x:Name="platform" Header="Platform" CanUserResize="False"
ItemsSource="{Binding Platform}"
SelectedValueBinding="{Binding Path=Platform.PlatformId}"
SelectedValuePath="PlatformId"
DisplayMemberPath="PlatformName" Width="100">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding Path=Platform.PlatformName}" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
</DataGridComboBoxColumn>
我看到带有值的保管箱,但是在我尝试接收DataGrid.ItemsSource
列平台时选择了任何值后,平台为空。我做错了什么?我试图将列更改为带有组合框的模板 - 结果相同。我将不胜感激任何帮助或至少是深入研究的方向。