zoukankan      html  css  js  c++  java
  • SilverLight:基础控件使用(3)-DataGrid控件

    ylbtech-SilverLight-Basic-Control:基础控件使用(3)-DataGrid控件

     DataGrid控件-后台绑定

    • 自动生成表列
    • 不自动生成表列
    1.A,返回顶部Person类(数据源提供者)
    1,
    /// <summary>
    /// 人员类
    /// </summary>    
    public class Person
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 年龄
        /// </summary>
        public int Age { get; set; }
    
        /// <summary>
        /// 空参构造
        /// </summary>
        public Person() { }
    
        /// <summary>
        /// 获取所有员工
        /// </summary>
        /// <returns></returns>
        public static IList<Person> GetAll()
        {
            #region 人员集合数据源
            IList<Person> dals = new List<Person>();
            dals.Add(new Person() { Id = 101, Name = "rain", Age = 24 });
            dals.Add(new Person() { Id = 102, Name = "mf", Age = 21 });
            dals.Add(new Person() { Id = 103, Name = "xy", Age = 27 });
            dals.Add(new Person() { Id = 104, Name = "tly", Age = 30 });
            #endregion
            return dals;
        }
    }
    View Code

    4,

    1.B,返回顶部 DataGrid控件绑定数据源-【AutoGenerateColumns=True】-自动生成表列
    1,
    <data:DataGrid AutoGenerateColumns="True" Height="200" HorizontalAlignment="Left" Margin="108,82,0,0" 
                    Name="dataGrid1" VerticalAlignment="Top" Width="200" IsEnabled="True" DataContext="{Binding}" />

    2,Name,Height,Width,

    AutoGenerateColumns[自动生成表列]=True|False
    3,
    namespace SilverlightApplication3
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                
                //调用方法
                LoadData();
            }
            /// <summary>
            /// 加载数据
            /// </summary>
            private void LoadData()
            {
                this.dataGrid1.ItemsSource = Person.GetAll();   //绑定数据源
            }
        }
        /// <summary>
        /// 人员类
        /// </summary>    
        public class Person
        {
            /// <summary>
            /// 编号
            /// </summary>
            public int Id { get; set; }
            /// <summary>
            /// 姓名
            /// </summary>
            public string Name { get; set; }
            /// <summary>
            /// 年龄
            /// </summary>
            public int Age { get; set; }
    
            /// <summary>
            /// 空参构造
            /// </summary>
            public Person() { }
    
            /// <summary>
            /// 获取所有员工
            /// </summary>
            /// <returns></returns>
            public static IList<Person> GetAll()
            {
                #region 人员集合数据源
                IList<Person> dals = new List<Person>();
                dals.Add(new Person() { Id = 101, Name = "rain", Age = 24 });
                dals.Add(new Person() { Id = 102, Name = "mf", Age = 21 });
                dals.Add(new Person() { Id = 103, Name = "xy", Age = 27 });
                dals.Add(new Person() { Id = 104, Name = "tly", Age = 30 });
                #endregion
                return dals;
            }
        }
    }
    View Code

    4,

    1.C,返回顶部DataGrid控件绑定数据源-【AutoGenerateColumns=False】-不自动生成表列
    1,
    <data:DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="108,82,0,0" 
            Name="dataGrid1" VerticalAlignment="Top" Width="200" IsEnabled="True" DataContext="{Binding}" >
        <data:DataGrid.Columns>
            <data:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" 
                                        Header="编号" Binding="{Binding Id}" IsReadOnly="True" />
            <data:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" 
                                        Header="姓名" Binding="{Binding Name}" />
            <data:DataGridTextColumn  CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" 
                                        Header="年龄" Binding="{Binding Age}" />
        </data:DataGrid.Columns>
    </data:DataGrid>

    2,Name,Height,Width,

    AutoGenerateColumns,Header[列头名称],Binding[{Binding 属性名称}],IsReadOnly
    3,代码同上 1.B.3
    4,
    1.D,返回顶部
     
    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    set集合 深浅拷贝
    2015 ACM/ICPC Asia Regional Changchun Online Pro 1005 Travel (Krsukal变形)
    2015 ACM/ICPC Asia Regional Changchun Online Pro 1002 Ponds(拓扑排序+并查集)
    Codeforces Round #319 (Div. 2) B Modulo Sum (dp,鸽巢)
    Codeforces Round #319 (Div. 2) C Vasya and Petya's Game (数论)
    UVA 11468 Substring (AC自动机)
    UVA11019 Matrix Matcher (AC自动机)
    UVALive 4670 Dominating Patterns (AC自动机)
    UVALive 3026 Period (KMP算法简介)
    UVA 11732 strcmp() Anyone (Trie+链表)
  • 原文地址:https://www.cnblogs.com/ylbtech/p/3398217.html
Copyright © 2011-2022 走看看