当前位置:   article > 正文

MVVM模式下ComboBox绑定

MVVM模式下ComboBox绑定

定义 :

 

  1. class CommonBox
  2.     {
  3.         public string Namepath { get; set; }
  4.         public int Value { get; set; }
  5.     }
  1. //检测线路
  2. public List<CommonBox> checkLines { get; set; }
  3. public CommonBox checkLine { get; set; }
  4. this.checkLines = new List<CommonBox>();
  5. this.checkLines.Add(new CommonBox() { Namepath = "线路1", Value = 1 });
  6. this.checkLines.Add(new CommonBox() { Namepath = "线路2", Value = 1 });
  7. this.checkLine = this.checkLines[0];


xaml

 ItemsSource 绑定数据源,

 SelectedItem 当前项,

checkLine.Namepath != " " 判断当前项目是不是为空

 

  1. <Label Content="检测线路:" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top"/>
  2. <ComboBox HorizontalAlignment="Left" Margin="61,10,0,0" VerticalAlignment="Top" Width="120"
  3. ItemsSource="{Binding checkLines}"
  4. DisplayMemberPath="Namepath"
  5. SelectedItem="{Binding checkLine}"/>

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/928580
推荐阅读
相关标签
  

闽ICP备14008679号