Click here to Skip to main content
15,888,803 members
Articles / Desktop Programming / WPF

A C# WPF .NET 4.0 "DataGrid" with Persistent Controls in Cells

Rate me:
Please Sign up or sign in to vote.
4.29/5 (10 votes)
29 Aug 2011CPOL10 min read 47.6K   2.4K   28  
A DataGrid lookalike that has persistent controls in cells
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:local="clr-namespace:PersistDataGrid"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <SolidColorBrush x:Key="DGP_BorderColor" Color="#A7A6AA"/>
    <GridLength x:Key="DGP_Head_Height">23.0</GridLength>
    <GridLength x:Key="DGP_Row_Height">21.0</GridLength>
    <Style  x:Key="DGP_Head_UpArrowStyle" TargetType="{x:Type Path}">
        <Setter Property="Data" Value="M 0 5 L 3.5 1 L 7 5 Z"/>
        <Setter Property="Width" Value="10"/>
        <Setter Property="Fill" Value="#5B6473"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>
    <Style  x:Key="DGP_Head_DownArrowStyle" TargetType="{x:Type Path}">
        <Setter Property="Data" Value="M 0 1 L 3.5 5 L 7 1 Z"/>
        <Setter Property="Width" Value="10"/>
        <Setter Property="Fill" Value="#5B6473"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>
    <LinearGradientBrush x:Key="DGP_Head_NormalBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFFFFF" Offset="0.0"/>
                <GradientStop Color="#B0C0D3" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="DGP_Head_NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#F2F2F2" Offset="0.0"/>
                <GradientStop Color="#D5D5D5" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="DGP_Head_HighlightBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFFFFF" Offset="0.0"/>
                <GradientStop Color="#FFFFFF" Offset="0.5"/>
                <GradientStop Color="#B0C0D3" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="DGP_Head_HighlightBorderBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#A5ACB2" Offset="0.0"/>
                <GradientStop Color="#A4A5B2" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>
<!-- All Below is duplicated in all Theme *.xaml files -->
    <Style  x:Key="DGP_Head_Style" TargetType="{x:Type Border}">
        <Setter Property="Background" Value="{StaticResource DGP_Head_NormalBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource DGP_Head_NormalBorderBrush}"/>
        <Style.Triggers>
            <Trigger Property="Border.IsMouseOver" Value="true">
                <Setter Property = "Background" Value="{StaticResource DGP_Head_HighlightBrush}"/>
                <Setter Property = "BorderBrush" Value="{StaticResource DGP_Head_HighlightBorderBrush}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="{x:Type local:Header}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Header}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Border Name="HeaderBorder" Style="{StaticResource DGP_Head_Style}" BorderThickness="1,0,0,1">
                                <Label Name="Title"/>
                            </Border>
                            <Path Name="Arrow"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions