Create a ListView control that uses a GridView view mode to display a collection of DateTime objects. : ListView « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » ListViewScreenshots 
Create a ListView control that uses a GridView view mode to display a collection of DateTime objects.
Create a ListView control that uses a GridView view mode to display a collection of DateTime objects.
  

<Window x:Class="WpfApplication1.Window1"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ds="clr-namespace:WpfApplication1">
  <Window.Resources>
    <ObjectDataProvider x:Key="myDateCollectionDataSource" ObjectType="{x:Type ds:myDateCollection}"/>
    <Style x:Key="GridViewColumnHeaderGripper" TargetType="{x:Type Thumb}">
      <Setter Property="Height" Value="{Binding Path=ActualHeight,RelativeSource={RelativeSource TemplatedParent}}"/>
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Thumb}">
            <Border>
              <Rectangle HorizontalAlignment="Center" Width="1" Fill="Black"/>
            </Border>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
    <Style x:Key="myControlTemplateStyle" TargetType="{x:Type GridViewColumnHeader}">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
            <Grid Background="LightBlue">
              <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <CheckBox></CheckBox>
                <TextBlock Text="{TemplateBinding Content}" FontSize="16" Foreground="DarkBlue"/>
              </DockPanel>
              <Canvas>
              <Thumb x:Name="PART_HeaderGripper"
                     Style="{StaticResource GridViewColumnHeaderGripper}"
                     Background="Transparent"
                     />
            </Canvas>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
      <Setter Property="Background" Value="LightBlue"/>
    </Style>

    <DataTemplate x:Key="myHeaderTemplate">
      <DockPanel>
        <CheckBox/>
        <TextBlock FontSize="16" Foreground="DarkBlue">
          <TextBlock.Text>
            <Binding/>
          </TextBlock.Text>
        </TextBlock>
      </DockPanel>
    </DataTemplate>

    <DataTemplate x:Key="myCellTemplateDay">
      <DockPanel>
        <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
          <TextBlock.Text>
            <Binding Path="Day"/>
          </TextBlock.Text>
        </TextBlock>
      </DockPanel>
    </DataTemplate>

    <DataTemplate x:Key="myCellTemplateMonth">
      <DockPanel>
        <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
          <TextBlock.Text>
            <Binding Path="Month"/>
          </TextBlock.Text>
        </TextBlock>
      </DockPanel>
    </DataTemplate>
    <DataTemplate x:Key="myCellTemplateYear">
      <DockPanel>
        <TextBlock Foreground="DarkBlue" HorizontalAlignment="Center">
          <TextBlock.Text>
            <Binding Path="Year"/>
          </TextBlock.Text>
        </TextBlock>
      </DockPanel>
    </DataTemplate>
  </Window.Resources>
  <StackPanel>
      <ListView ItemsSource="{Binding Source={StaticResource myDateCollectionDataSource}}"
                HorizontalAlignment="Center">
        <ListView.View>
          <GridView>
            <GridViewColumn Header="Year" Width="80"
                  HeaderContainerStyle="{StaticResource myHeaderStyle}"
                  HeaderTemplate="{StaticResource myHeaderTemplate}"
                  CellTemplate="{StaticResource myCellTemplateYear}"/>
            <GridViewColumn Header="Month" Width="80"
                  HeaderContainerStyle="{StaticResource myHeaderStyle}"
                  HeaderTemplate="{StaticResource myHeaderTemplate}"
                  DisplayMemberBinding="{Binding Path=Month}"/>
            <GridViewColumn Header="Day" Width="80"
                  HeaderContainerStyle="{StaticResource myHeaderStyle}"
                  HeaderTemplate="{StaticResource myHeaderTemplate}"
                  CellTemplate="{StaticResource myCellTemplateDay}"/>
          </GridView>
        </ListView.View>
      </ListView>
  </StackPanel>

</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Collections.ObjectModel;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {}

    public class myDateCollection :
            ObservableCollection<DateTime>
    {
        public myDateCollection()
        {
            Add(new DateTime(200511));
            Add(new DateTime(200481));
            Add(new DateTime(2003124));
            Add(new DateTime(2004218));
            Add(new DateTime(2004630));
        }
    }
}

   
    
  
Related examples in the same category
1.Create a ListView control that implements a GridView view with CheckBox controls for each row.Create a ListView control that implements a GridView view with CheckBox controls for each row.
2.Use ArrayList as the ListView ItemSourceUse ArrayList as the ListView ItemSource
3.Create a ListView control that implements a GridView view mode, displays content in groups.Create a ListView control that implements a GridView view mode, displays content in groups.
4.ListView and ListViewItemListView and ListViewItem
5.ListView columnsListView columns
6.Populating ListView rowsPopulating ListView rows
7.Set Binding ListView.ItemsSourceProperty to ListViewSet Binding ListView.ItemsSourceProperty to ListView
8.ListView using GridView.HeaderTemplate and GridViewColumn.CellTemplate propertiesListView using GridView.HeaderTemplate and GridViewColumn.CellTemplate properties
9.Get Bounded item from ListViewGet Bounded item from ListView
10.Create Binding for ListView in codeCreate Binding for ListView in code
11.Use three TextBlocks in one ListViewItemUse three TextBlocks in one ListViewItem
12.Create a ListView control that uses a GridView view mode to display dates.Create a ListView control that uses a GridView view mode to display dates.
13.Use Path to reference Bounded object in ItemSourceUse Path to reference Bounded object in ItemSource
14.Enables sorting of data in ascending or descending order according to the contents of one column.Enables sorting of data in ascending or descending order according to the contents of one column.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.