Silverlight控件DataGrid用法总结

常规的用法先总结一下。前台设置列名,列宽,列高,绑定数据。后台构造数据源,设置是否排序等。
其他的小技巧遇到了总结到此文。如图:

uc_DataGrid.xaml

ExpandedBlockStart.gif 大气象
< UserControl  x:Class ="HCLoad.uc_DataGrid"
    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 ="True"  Height ="100"  HorizontalAlignment ="Left"  Margin ="10,10,0,0"  Name ="dgList"  VerticalAlignment ="Top"  Width ="300" >
            
< sdk:DataGrid.Columns >
                
< sdk:DataGridTextColumn  Header ="Id"  Binding =" {Binding 编号} "  Width ="100" ></ sdk:DataGridTextColumn >
            
</ sdk:DataGrid.Columns >
        
</ sdk:DataGrid >
    
</ Grid >
</ UserControl >

 

uc_DataGrid.xaml.cs

ExpandedBlockStart.gif 大气象
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  HCLoad
{
    
public   partial   class  uc_DataGrid : UserControl
    {
        
public  uc_DataGrid()
        {
            InitializeComponent();
            Bind();
        }
        List
< Model >  list  =   new  List < Model > ();
        
public   class  Model
        {
            
public   int  ID {  get set ; }
            
public   string  名称 {  get set ; }
            
public  Model() { }
            
public  Model( int  _ID,  string  _名称)
            {
                ID 
=  _ID;
                名称 
=  _名称;
            }
        }
        
private   void  Bind()
        {
            list.Clear();
            list.Add(
new  Model( 1 " 名1 " ));
            list.Add(
new  Model( 2 " 名2 " ));
            list.Add(
new  Model( 3 " 名3 " ));

            dgList.ItemsSource 
=  list;
            dgList.CanUserSortColumns 
=   false ; // 设置不排序
            dgList.Height  =   150 ;
            dgList.IsReadOnly 
=   true ; // 设置只读,选择的时候,不能进入编辑状态
        }
    }
}

 

 

转载于:https://www.cnblogs.com/greatverve/archive/2010/07/15/silerlight-datagrid.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值