其他分享
首页 > 其他分享> > WPF数据绑定

WPF数据绑定

作者:互联网

1.<ListBox x:Name="listName" Width="248" Height="60">
                <ListBoxItem Content="张三"/>
                <ListBoxItem Content="李四"/>
                <ListBoxItem Content="王五"/>
                <ListBoxItem Content="赵柳"/>
      </ListBox>
       <TextBlock Width="248" Height="24" Text="你所选中的人员名称:" />
       <TextBlock Width="248" Height="24" Text="{Binding ElementName=listName, Path=SelectedItem.Content}">

2. <DataGrid x:Name="dsGrid" AutoGenerateColumns="False" ItemsSource="{Binding Students}" CanUserAddRows="False">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Name}" Width="100" Header="名称" />
                <DataGridTextColumn Binding="{Binding Age}" Width="80" Header="年龄" />
                <DataGridTextColumn Binding="{Binding Country}" Width="150" Header="国家" />
            </DataGrid.Columns>
        </DataGrid>

 

 public class Student 
    {     

       public string Name { get; set ;}

        public string Age { get; set ; }
        public string Country { get; set; }

    }

 public List<Student> GetStudentList()

        {

            Student liang = new Student();

            liang.Age = "1";

            liang.Name = "丘";

            liang.Country = "中国";

    }

 this.DataContext = this;

List<Student> students = GetStudentList();

dsGrid.ItemsSource = students;

 

标签:set,string,get,绑定,liang,Student,WPF,数据,public
来源: https://www.cnblogs.com/houwang/p/15226131.html