后台代码编写 ,为表格绑定数据:
- 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 = "飞羽", Age = 12, 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,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>
--------------------------------------
偕行软件欢迎您光临我们的博客
我们的官网:http://www.udchn.com
我们的空白开发框架:HTTP://DEMO.UDCHN.COM:8082
我们的集团式人力资源管理系统:HTTP://DEMO.UDCHN.COM:8081