silverlight datagrid列宽自动填充

silverlight datagrid列宽自动填充,第1张

概述using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;us
using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;namespace SilverlightApplication90{    public partial class MainPage : UserControl    {        private DataGrID TestDataGrID = null;        public MainPage()        {            InitializeComponent();            TestDataGrID = new DataGrID();            TestDataGrID.autoGenerateColumns = true;            TestDataGrID.SizeChanged += new SizeChangedEventHandler(TestDataGrID_SizeChanged);            LayoutRoot.Children.Add(TestDataGrID);            this.Loaded += new RoutedEventHandler(MainPage_Loaded);        }        /// <summary>        /// 当DataGrID的Size改变时触发事件,使第二列的宽度填充DataGrID剩余的空间。        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        voID TestDataGrID_SizeChanged(object sender,SizeChangedEventArgs e)        {            double dataGrIDWIDth = TestDataGrID.ActualWIDth;            double otherColumnsWIDth = TestDataGrID.Columns[0].ActualWIDth;            double borderThickness = TestDataGrID.borderThickness.left + TestDataGrID.borderThickness.Right;            TestDataGrID.Columns[1].WIDth = new DataGrIDLength(dataGrIDWIDth - otherColumnsWIDth - borderThickness);        }        voID MainPage_Loaded(object sender,RoutedEventArgs e)        {            List<Student> items = GetStudents();            TestDataGrID.ItemsSource = items;        }        /// <summary>        /// 获取数据源        /// </summary>        /// <returns></returns>        private List<Student> GetStudents()        {            List<Student> items = new List<Student>();            for (int i = 0; i < 20; i++)            {                items.Add(new Student(i,"张三" + i));            }            return items;        }    }    public class Student    {        public Student() { }        public Student(int _studentID,string _studentname)        {            this.StudentID = _studentID;            this.Studentname = _studentname;        }        private int studentID;        public int StudentID        {            get { return studentID; }            set { studentID = value; }        }        private string studentname;        public string Studentname        {            get { return studentname; }            set { studentname = value; }        }    }}
总结

以上是内存溢出为你收集整理的silverlight datagrid列宽自动填充全部内容,希望文章能够帮你解决silverlight datagrid列宽自动填充所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1022885.html

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

发表评论

登录后才能评论

评论列表(0条)

保存