定义 :
class CommonBox
{
public string Namepath { get; set; }
public int Value { get; set; }
}
//检测线路
public List<CommonBox> checkLines { get; set; }
public CommonBox checkLine { get; set; }
this.checkLines = new List<CommonBox>();
this.checkLines.Add(new CommonBox() { Namepath = "线路1", Value = 1 });
this.checkLines.Add(new CommonBox() { Namepath = "线路2", Value = 1 });
this.checkLine = this.checkLines[0];
xaml
ItemsSource 绑定数据源,
SelectedItem 当前项,
checkLine.Namepath != " " 判断当前项目是不是为空
<Label Content="检测线路:" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top"/>
<ComboBox HorizontalAlignment="Left" Margin="61,10,0,0" VerticalAlignment="Top" Width="120"
ItemsSource="{Binding checkLines}"
DisplayMemberPath="Namepath"
SelectedItem="{Binding checkLine}"/>