Silverlight Study Notes 1-ComboBox

Source: Internet
Author: User

1. Simple ComboBox binding

<ComboBox grid. row = "1" grid. column = "3" Height = "20" horizontalalignment = "Left" verticalignment = "TOP" name = "lstsex" width = "100" margin = "5, 4, 0, 0 "selectedindex =" 0 "> <comboboxitem content =" sir "/> <comboboxitem content =" "/> </ComboBox>

2. ComboBox Data Binding

2.1 Xmal

<ComboBox Grid.Row="0" Grid.Column="3" Height="20" HorizontalAlignment="Left"  VerticalAlignment="Top" Name="Comb1" Width="100" Margin="5,8,0,0"></ComboBox>

2.2 Data Source

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 background code

private void BindStudent(){    Comb1.ItemsSource = new Students().getStudent();    Comb1.DisplayMemberPath = "Name";}

3 ComboBox assignment

3.1 The items of ComboBox is in a fixed state

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 when the items of ComboBox is always changing

Student. Name and name may be modified at any time.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.