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

后台代码编写 ,为表格绑定数据:

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 SilverlightApplication4{    public partial class MainPage : UserControl    {        public class Person//定义类        {            string name;            public string name            {                get { return name; }                set { name = value; }            }            int age;            public int Age            {                get { return age; }                set { age = value; }            }            bool isMan;            public bool IsMan            {                get { return isMan; }                set { isMan = value; }            }        }        public MainPage()//页面初始化        {            InitializeComponent();            List<Person> itemList = new List<Person>();            itemList.Add(new Person { name = "当当",Age = 45,IsMan = true });            itemList.Add(new Person { name = "大雄",Age = 3,IsMan = false });            itemList.Add(new Person { name = "小新",Age = 12,IsMan = false });            itemList.Add(new Person { name = "丁丁",Age = 32,IsMan = true });            itemList.Add(new Person { name = "Gaga",Age = 56,IsMan = true });            itemList.Add(new Person { name = "司空",Age = 33,IsMan = false });            itemList.Add(new Person { name = "lfy",Age = 22,IsMan = true });            itemList.Add(new Person { name = "lili",Age = 34,IsMan = true });            itemList.Add(new Person { name = "飞羽",IsMan = false });            dataGrID1.ItemsSource = itemList;        }    }}


前台表格样式编写:

<UserControl x:Class="SilverlightApplication4.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="300" d:DesignWIDth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">    <GrID x:name="LayoutRoot" Background="White">                        <sdk:DataGrID autoGenerateColumns="False" Height="209" HorizontalAlignment="left" margin="12,12,0" name="dataGrID1" VerticalAlignment="top" WIDth="376">            //表格划分列            <sdk:DataGrID.Columns>                <sdk:DataGrIDTemplateColumn header="名字">                    <sdk:DataGrIDTemplateColumn.CellTemplate>                        <DataTemplate>                         <TextBlock Text="{Binding name}"/>                           </DataTemplate>                    </sdk:DataGrIDTemplateColumn.CellTemplate>                </sdk:DataGrIDTemplateColumn>            </sdk:DataGrID.Columns>                        //显示每列详细数据            <sdk:DataGrID.RowDetailstemplate>                <DataTemplate>                    <StackPanel>                        <TextBlock Text="{Binding Age}"/>                        <TextBlock Text="{Binding IsMan}"/>                    </StackPanel>                </DataTemplate>            </sdk:DataGrID.RowDetailstemplate>                                </sdk:DataGrID>            </GrID></UserControl>
总结

以上是内存溢出为你收集整理的Silverlight学习笔记三:表格控件DataGrid全部内容,希望文章能够帮你解决Silverlight学习笔记三:表格控件DataGrid所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1067647.html

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

发表评论

登录后才能评论

评论列表(0条)

保存