点滴积累,融会贯通

-----喜欢一切有兴趣的东西

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

首先:这版本需要.NetFrameWork SP1的支持

WPF Toolkit - February 2010 Release

下载地址:http://wpf.codeplex.com/releases/view/40535

下载安装文件,安装以后,在目录:

C:\Program Files\WPF Toolkit\v3.5.50211.1

下面有需要的dll

 

接下来开始使用介绍:

主要给DataGrid添加了4种类型的列:DataGridTextColumn,DataGridHyperlinkColumn,DataGridCheckBoxColumn,DataGridComboBoxColumn

1 创建WPF Application 程序,引用WPFToolkit.dll

2 xaml文件如下:

<Window x:Class="WpfAppTest.WPFDataGrid"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys
="clr-namespace:System;assembly=mscorlib" 
    xmlns:toolkit
="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:myWPFDataGrid
="clr-namespace:WpfAppTest;assembly=WpfAppTest"
    Title
="WPFDataGrid" Height="351" Width="647" Loaded="Window_Loaded">

    
<Window.Resources>
        
<ObjectDataProvider x:Key="myEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            
<ObjectDataProvider.MethodParameters>
                
<x:Type TypeName="myWPFDataGrid:sampleType"/>
            
</ObjectDataProvider.MethodParameters>
        
</ObjectDataProvider>
    
</Window.Resources>

    
<Grid>
        
<toolkit:DataGrid Name="SampleDataGrid" AutoGenerateColumns="False" ItemsSource="{Binding}">
            
<toolkit:DataGrid.Columns>
                
<toolkit:DataGridTextColumn Header="ID"  Binding="{Binding ID}"/>
                
<toolkit:DataGridTextColumn Header="Name" Binding="{Binding Name}" />
                
<toolkit:DataGridHyperlinkColumn Header="Link" Binding="{Binding Link}"  ContentBinding="{Binding Link}" />
                
<toolkit:DataGridCheckBoxColumn Header="IsBool" Binding="{Binding IsBool}" />
                
<toolkit:DataGridComboBoxColumn Header="MyType" SelectedItemBinding="{Binding MyType}" ItemsSource="{Binding Source={StaticResource myEnum}}" TextBinding="{Binding MyType}" />

            
</toolkit:DataGrid.Columns>

        
</toolkit:DataGrid>
    
</Grid>
</Window>

 

2 c#文件如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace WpfAppTest
{
    
/// <summary>
    
/// Interaction logic for WPFDataGrid.xaml
    
/// </summary>
    public partial class WPFDataGrid : Window
    {
        
public WPFDataGrid()
        {
            InitializeComponent();
        }

        
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt 
= new DataTable();
            DataColumn dc 
= new DataColumn("ID"typeof(System.String));
            dt.Columns.Add(dc);
            dc 
= new DataColumn("Name"typeof(System.String));
            dt.Columns.Add(dc);
            dc 
= new DataColumn("Link"typeof(System.String));
            dt.Columns.Add(dc);
            dc 
= new DataColumn("IsBool"typeof(System.Boolean));
            dt.Columns.Add(dc);
            dc 
= new DataColumn("MyType"typeof(sampleType));
            dt.Columns.Add(dc);
            
for (int i = 0; i < 10; i++)
            {
                dt.Rows.Add(
new object[] { i.ToString(), "Name" + i.ToString(), "Link" + i.ToString(), true, sampleType.C });
            }
            DataSet ds 
= new DataSet();
            ds.Tables.Add(dt);

            SampleDataGrid.DataContext 
= ds.Tables[0];
        }
    }

    
public enum sampleType
    { A, B, C, D, E };
}

 

 

posted on 2010-04-01 14:27  小寒  阅读(6969)  评论(0编辑  收藏  举报