SilverLight 学习笔记一之ComboBox

SilverLight 学习笔记一之ComboBox,第1张

概述1,ComboBox简单 绑定 <ComboBox Grid.Row="1" Grid.Column="3" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top" Name="lstSex" Width="100" Margin="5,4,0,0" SelectedIndex="0"> <ComboBoxIte

1,ComboBox简单 绑定

 <ComboBox GrID.Row="1" GrID.Column="3"  Height="20" HorizontalAlignment="left"  VerticalAlignment="top" name="lstSex" WIDth="100" margin="5,4,0" Selectedindex="0">    <ComboBoxItem Content="先生" />    <ComboBoxItem Content="女士" /></ComboBox>

2,ComboBox数据绑定

2.1 xmal

<ComboBox GrID.Row="0" GrID.Column="3" Height="20" HorizontalAlignment="left"  VerticalAlignment="top" name="Comb1" WIDth="100" margin="5,8,0"></ComboBox>

2.2 数据源

public class Student{    public string name    {        set;        get;    }}public class Students{    public List<Student> StudentList    {        set;        get;    }	    public List<Student> getStudent()    {        StudentList= new List<Student>              {                new Student(){name="X1"},new Student(){name="X2"},new Student(){name="X3"}            };        return StudentList;    }}

2.2 后台代码

private voID BindStudent(){    Comb1.ItemsSource = new Students().getStudent();    Comb1.displayMemberPath = "name";}

3  ComboBox赋值

3.1 ComboBox的Items处于固定的状态

Comb1.ItemsSource = new Students().getStudent();switch (usermodel.UserDepartment ){    case "X1":        this.Comb1 .Selectedindex =0;        break;    case "X2":        this.Comb1 .Selectedindex =1;        break;                        case "X3":        this.Comb1 .Selectedindex =2;        break;                                    }

3.2  当ComboBox的Items时时处于变化的状态

到数据库查询到student.name,name可能随时被修改

foreach(Student item in Comb1.Items){    if(item.name == student.name)     {        Comb1.SelectedItem = item;    }}
总结

以上是内存溢出为你收集整理的SilverLight 学习笔记一之ComboBox全部内容,希望文章能够帮你解决SilverLight 学习笔记一之ComboBox所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1073203.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存