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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    加快火狐启动速度的几种方法 Leone
    我国的社保到底是多交好,还是少交好? Leone
    “情商”和“智商”究竟有哪些区别? Leone
    Atitti 知识图谱构建方法attilax 总结
    Atitit 知识图谱的数据来源
    Atitit java 二维码识别 图片识别
    Atitit 跨平台异常处理(2)异常转换 java c# js异常对象结构比较and转换
    Atitit 异常机制与异常处理的原理与概论
    Atitti knn实现的具体四个距离算法 欧氏距离、余弦距离、汉明距离、曼哈顿距离
    屏幕取词技术实现原理
  • 原文地址:https://www.cnblogs.com/ylbtech/p/3398217.html
Copyright © 2011-2022 走看看