我有一个包含各种类型成员的班级InfoField
。我想将ObservableCollection<InfoField>
属性绑定到某种WPF控制器。
我一直在使用ListView
进行测试,但我不确定这是正确的方法。从我所看到的情况来看,我在使用ListView
获得第二和第四点时遇到了麻烦。有人知道使用哪种控件吗?
ShowRpm ShowCurrent ShowTemperature Direction
Motor1 (checkbox) (checkbox) (checkbox) (combobox)
Motor2 (checkbox) (checkbox) (checkbox) (combobox)
Motor3 (checkbox) (checkbox) (checkbox) (combobox)
...
MotorN (checkbox) (checkbox) (checkbox) (combobox)
C#:
public class InfoField {
public bool ShowRpm { get; set; }
public bool ShowCurrent { get; set; }
public bool ShowTemperature { get; set; }
public Direction Direction { get; set; }
}
public enum Direction {
Horizontal,
Vertical
}
答案 0 :(得分:1)
我建议你使用DataGrid。通过一些自定义,您应该能够统计所有选项。这是您可以使用的起点
//Collection for the datagrid
public ObservableCollection<InfoField> infoFieldData;
public MainWindow()
{
InitializeComponent();
infoFieldData = new ObservableCollection<InfoField>();
InfoField info1 = new InfoField();
InfoField info2 = new InfoField();
infoFieldData.Add(info1);
infoFieldData.Add(info2);
dataGrid.ItemsSource = infoFieldData;
dataGrid.Items.Refresh();
}
public class InfoField
{
public bool ShowRpm { get; set; }
public bool ShowCurrent { get; set; }
public bool ShowTemperature { get; set; }
public Direction Direction { get; set; }
}
public enum Direction
{
Horizontal,
Vertical
}
DataGrid XAML
<DataGrid x:Name="dataGrid" HorizontalAlignment="Left" VerticalAlignment="Top" CanUserAddRows="False"/>
对于具有行标题的第2点,此问题为DataGrid Row Header WPF
对于第4点,这是How do I capture “Click” events on a DataGrid column headers