public partial class Page : UserControl { public Page() { // 需要初始化变量 InitializeComponent(); Cmbs_Items_Add(); } public class CombItem { public string Value { get; set; } public string Text { get; set; } } /// <summary> /// 给combox赋值 /// </summary> private void Cmbs_Items_Add() { //给 房屋标识 赋值 this.cmbs.UpdateLayout();//设置this.cmbs.UpdateLayout();确保 UIElement 的所有子对象位置都正确地进行了布局更新 List<CombItem> ctg = new List<CombItem>() { new CombItem { Value="", Text="" }, new CombItem { Value="0", Text="正常" }, new CombItem { Value="1", Text="新增" }, new CombItem { Value="2", Text="已拆" } }; this.cmbs.ItemsSource = ctg; cmbs.DisplayMemberPath = "Text";//绑定Text值 this.cmbs.SelectedValuePath = "Value";//指定Value值 } #region ========设定当前选择项======== CombItem emp = new CombItem() { Value = "", Text = "" }; //this.comboBox1.SelectedItem = emp; //这样设不起作用. List<CombItem> list = this.cmbs.ItemsSource as List<CombItem>; int flag = -1; for (int i = 0; i < list.Count; i++) { if (list[i].Value == emp.Value && list[i].Text == emp.Text) { flag = i; break; } } this.cmbs.SelectedIndex = flag; #endregion //获取combox选中的值 CombItem emp = this.cmbs.SelectedItem as CombItem; }
Silverlight中为ComboBox设定当前选择项、数据绑定、取值。
原创mb6125f21d37d0e 博主文章分类:Silverlight ©著作权
©著作权归作者所有:来自51CTO博客作者mb6125f21d37d0e的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:StackPanel布局
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
qt comboBox在设计其中添加选择项
qt comboBox在设计其中添加选择项1. 在qtCreator设计器中拖入ComboxBox控件2.右键点击combox,选项
QtCreator QComboBox 右键 控件 -
wpf combox的绑定与设置选择项
<br />绑定的代码 :<br /> <br /> private void bindType()<br /> {<br /> Code.Dao.
wpf list office string i++