Click here to Skip to main content
15,886,422 members
Articles / Desktop Programming / WPF

WPF: A TimeLineControl

Rate me:
Please Sign up or sign in to vote.
4.97/5 (162 votes)
14 Apr 2010CPOL19 min read 348.4K   5.5K   282  
Simple WPF TimeLineControl That I Think May Be Useful
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!-- scroll viewer -->
    <Style x:Key="ScrollViewerStyle" TargetType="{x:Type ScrollViewer}">
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="VerticalScrollBarVisibility" Value="Hidden" />
    </Style>

    <!-- All ToolTips-->
    <Style TargetType="{x:Type ToolTip}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToolTip}">
                    <Border BorderBrush="White" CornerRadius="3" 
                            Margin="0"
                            Background="Black" BorderThickness="2"
                            HorizontalAlignment="Center" 
                            VerticalAlignment="Center">
                        <ContentPresenter Content="{TemplateBinding Content}" 
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center" 
                            Margin="5" TextBlock.Foreground="White" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Navigation Button-->
    <Style x:Key="leftButtonTemplateStyle"  TargetType="{x:Type Button}">
        <Setter Property="Width" Value="20"/>
        <Setter Property="Height" Value="20"/>
        <Setter Property="Margin" Value="5"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="ToolTip" Value="Navigate Back"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Ellipse x:Name="el" Width="20" Height="20" Fill="Black" Stroke="White"
                                 StrokeThickness="2" HorizontalAlignment="Center" 
                                 VerticalAlignment="Center"  />
                        <Label x:Name="lbl" HorizontalAlignment="Center" 
                                 VerticalAlignment="Center" 
                                 VerticalContentAlignment="Center"
                                 Margin="-2,-2,0,0"
                                 FontSize="11"
                                 FontFamily="Wingdings 3"
                                 Foreground="White"
                                 Content="t" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="el" Property="Stroke" Value="CornflowerBlue"/>
                            <Setter TargetName="lbl" Property="Foreground" Value="CornflowerBlue"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <LinearGradientBrush x:Key="TopBannerBackGround" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="Black" Offset="0.5"/>
        <GradientStop Color="#FF434343"/>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="TopBannerTextForeground" Color="White"/>
    <SolidColorBrush x:Key="TopBannerTextBorderBrush" Color="White"/>

    <!-- ScrollViewer Styles -->

    <!-- ScrollBarPageButton -->
    <Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="{DynamicResource transparentBackGround}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- VerticalScrolScrollBarThumbBar -->
    <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border 
          CornerRadius="2"
          Background="{TemplateBinding Background}"
          BorderBrush="{TemplateBinding BorderBrush}"
          BorderThickness="1" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- VerticalScrollBar -->
    <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid Background="{DynamicResource transparentBackGround}" >
            <Grid.RowDefinitions>
                <RowDefinition Height="0.00001*"/>
            </Grid.RowDefinitions>
            <Border
      Grid.RowSpan="1"
      CornerRadius="2"
      Background="{DynamicResource transparentBackGround}" />
            <Track
      Name="PART_Track"
      Grid.Row="1"
      IsDirectionReversed="true">
                <Track.DecreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageUpCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Name="thumb"
          Style="{StaticResource ScrollBarThumb}" 
          Margin="3,0,3,0"  
          Background="CornflowerBlue"
          BorderBrush="CornflowerBlue" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageDownCommand" />
                </Track.IncreaseRepeatButton>

            </Track>
        </Grid>
    </ControlTemplate>

    <!-- HorizontalScrollBar -->
    <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid Background="{DynamicResource transparentBackGround}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.00001*"/>
            </Grid.ColumnDefinitions>
            <Border
      Grid.ColumnSpan="1"
      CornerRadius="2"
      Background="{DynamicResource transparentBackGround}" />
            <Track 
      Name="PART_Track"
      Grid.Column="1"
      IsDirectionReversed="False">
                <Track.DecreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageLeftCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Name="thumb"
          Style="{StaticResource ScrollBarThumb}" 
          Margin="0,3,0,3"  
          Background="CornflowerBlue"
          BorderBrush="CornflowerBlue" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageRightCommand" />
                </Track.IncreaseRepeatButton>
            </Track>
        </Grid>
    </ControlTemplate>

    <!-- ScrollBar -->
    <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Width" Value="Auto"/>
                <Setter Property="Height" Value="14" />
                <Setter Property="Template" Value="{StaticResource HorizontalScrollBar}" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Width" Value="14"/>
                <Setter Property="Height" Value="Auto" />
                <Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <!-- ScrollViewerStyle -->
    <Style TargetType="{x:Type ScrollViewer}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="HorizontalScrollBarVisibility" Value="Visible" />
        <Setter Property="VerticalScrollBarVisibility" Value="Visible" />
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ContextMenu" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <ScrollContentPresenter Grid.Column="0"/>

                        <ScrollBar Name="PART_VerticalScrollBar"
                            Grid.Column="1"
                            Value="{TemplateBinding VerticalOffset}"
                            Maximum="{TemplateBinding ScrollableHeight}"
                            ViewportSize="{TemplateBinding ViewportHeight}"
                            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                        <ScrollBar Name="PART_HorizontalScrollBar"
                            Orientation="Horizontal"
                            Grid.Row="1"
                            Grid.Column="0"
                            Value="{TemplateBinding HorizontalOffset}"
                            Maximum="{TemplateBinding ScrollableWidth}"
                            ViewportSize="{TemplateBinding ViewportWidth}"
                            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



    <!-- Bar Grouping Styles-->
    <SolidColorBrush x:Key="graphSectionBar" Color="CornflowerBlue"/>





    <Style x:Key="graphSectionButtonStyle"  TargetType="{x:Type Button}">
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="ToolTip" Value="Drill Down Into This Area"/>
        <Setter Property="Template">
            <Setter.Value>

                <ControlTemplate TargetType="{x:Type Button}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="Timeline1">
                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
                                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                        <Storyboard x:Key="Timeline2">
                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
                                <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid Background="Black">

                        <Grid.RowDefinitions>
                            <RowDefinition Height="5"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>



                        <Rectangle Grid.Row="0" Fill="{StaticResource graphSectionBar}" 
                            Height="5" HorizontalAlignment="Stretch" Margin="-1,0,-1,0" />


                        
                        <Border x:Name="borderOuter" Grid.Row="2" BorderBrush="Transparent" 
                                BorderThickness="0" CornerRadius="0" Margin="-1,0,-1,0" 
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                            <Border x:Name="border" Background="#7F000000" 
                                    BorderBrush="Transparent" BorderThickness="0" CornerRadius="0">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="0.507*"/>
                                        <RowDefinition Height="0.493*"/>
                                    </Grid.RowDefinitions>
                                    <Border Opacity="0" HorizontalAlignment="Stretch" x:Name="glow" 
                                            Width="Auto" Grid.RowSpan="2" CornerRadius="0">
                                        <Border.Background>
                                            <RadialGradientBrush>
                                                <RadialGradientBrush.RelativeTransform>
                                                    <TransformGroup>
                                                        <ScaleTransform ScaleX="1.702" ScaleY="2.243"/>
                                                        <SkewTransform AngleX="0" AngleY="0"/>
                                                        <RotateTransform Angle="0"/>
                                                        <TranslateTransform X="-0.368" Y="-0.152"/>
                                                    </TransformGroup>
                                                </RadialGradientBrush.RelativeTransform>
                                                <GradientStop Color="#B28DBDFF" Offset="0"/>
                                                <GradientStop Color="#008DBDFF" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Border.Background>
                                    </Border>

                                    <Label x:Name="lblText" Width="Auto" Grid.RowSpan="2" 
                                       Margin="0"
                                       Padding="0"
                                       FontFamily="Tahoma" 
                                       Foreground="White" 
                                       FontWeight="Bold"
                                       FontSize="12" 
                                       HorizontalAlignment="Center" 
                                       HorizontalContentAlignment="Left"
                                       VerticalAlignment="Center" 
                                       VerticalContentAlignment="Center"
                                       Content="{TemplateBinding Content}"/>


                                    <Border HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="shine" 
                                            Width="Auto" CornerRadius="0">
                                        <Border.Background>
                                            <LinearGradientBrush EndPoint="0.494,0.889" StartPoint="0.494,0.028">
                                                <GradientStop Color="#99FFFFFF" Offset="0"/>
                                                <GradientStop Color="#33FFFFFF" Offset="1"/>
                                            </LinearGradientBrush>
                                        </Border.Background>
                                    </Border>
                                </Grid>
                            </Border>
                        </Border>


                    </Grid>



                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Opacity" TargetName="shine" Value="0.4"/>
                            <Setter Property="Background" TargetName="border" Value="#CC000000"/>
                            <Setter Property="Visibility" TargetName="glow" Value="Hidden"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource Timeline1}"/>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard x:Name="Timeline2_BeginStoryboard" 
                                                 Storyboard="{StaticResource Timeline2}"/>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" TargetName="lblText" Value="DarkGray"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>

            </Setter.Value>
        </Setter>
    </Style>





    <!--ITEM POP STYLES-->
    <SolidColorBrush x:Key="itemsPopupTitleColor" Color="White"/>
    
    <SolidColorBrush x:Key="itemsPopupBorderBrushColor" Color="White"/>


    <SolidColorBrush x:Key="itemsPopupBackgroundColor" Color="Black"/>


   
    <LinearGradientBrush x:Key="itemsPopupHeaderBackgroundColor"  EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF3E7EEF" Offset="1"/>
        <GradientStop Color="CornflowerBlue"/>
        <GradientStop Color="CornFlowerBlue" Offset="0.5"/>
        <GradientStop Color="#FF3E7EEF" Offset="0.526"/>
    </LinearGradientBrush>

    <Style x:Key="itemsPopupCloseButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Width" Value="20"/>
        <Setter Property="Height" Value="20"/>
        <Setter Property="Margin" Value="5"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="ToolTip" Value="Close items popup"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">

                    <Border x:Name="bord" 
								BorderBrush="Transparent" BorderThickness="1" 
								CornerRadius="5" Background="Transparent"
								HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

                        <Image HorizontalAlignment="Center" VerticalAlignment="Center"
                               Width="15" Height="15" Source="../Images/close.png"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="bord" Property="Background" 
                                    Value="Black"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



    <!-- ListBoxItem -->
    <Style x:Key="popupListBoxItemStyle" TargetType="ListBoxItem">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Grid x:Name="gridItem" Background="Transparent" 
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch">
                        <ContentPresenter/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <!-- ListBoxItem -->
    <Style x:Key="itemsListBoxStyle" TargetType="ListBox">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="ItemContainerStyle" Value="{StaticResource popupListBoxItemStyle}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Background" Value="Black"/>
    </Style>


    <!-- BreadCrumbStyles -->
    <Style x:Key="crumbLabel" TargetType="Label">
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="FontFamily" Value="Verdana"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontWeight" Value="Bold"/>
    </Style>


    <Style x:Key="crumbButton" TargetType="{x:Type Button}">
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">

                    <TextBlock x:Name="txt" Foreground="White" 
                               FontWeight="Bold"
                               Text="{TemplateBinding Content}"
                               FontSize="13" FontFamily="Verdana"
                               VerticalAlignment="Center"/>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="txt" Property="TextDecorations" 
                                    Value="Underline"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </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
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions