Click here to Skip to main content
15,892,161 members
Articles / Desktop Programming / WPF

C# WPF .NET 4.0 ArrowRepeatButton, NumericUpDown, and TimeCtrl Controls

Rate me:
Please Sign up or sign in to vote.
4.39/5 (11 votes)
14 Oct 2011CPOL16 min read 67.4K   3.4K   16  
User controls for entering either a time or a number within a range.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:UpDownCtrls"
                    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna"
                    x:Name="MyArrowButton">
    <local:ThicknessToMarginConverter x:Key="ThicknessToMarginConverter" />
    <Style TargetType="{x:Type local:ArrowRepeatButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ArrowRepeatButton}">
                    <Grid Margin="0,0,0,0">
                        <Microsoft_Windows_Themes:ScrollChrome x:Name="ScrollChrome" HasOuterBorder="false" 
                                                               Padding="0,0,0,0" SnapsToDevicePixels="False" ClipToBounds="True"
                                                               HorizontalAlignment="Stretch" RenderMouseOver="{TemplateBinding IsMouseOver}" 
                                                               RenderPressed="{TemplateBinding IsPressed}"
                                                               ThemeColor="Metallic"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ButtonArrowType" Value="Down">
                            <Setter TargetName="ScrollChrome" Property="Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph" Value="DownArrow"/>
                        </Trigger>
                        <Trigger Property="ButtonArrowType" Value="Up">
                            <Setter TargetName="ScrollChrome" Property="Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph" Value="UpArrow" />
                        </Trigger>
                        <Trigger Property="ButtonArrowType" Value="Left">
                            <Setter TargetName="ScrollChrome" Property="Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph" Value="LeftArrow" />
                        </Trigger>
                        <Trigger Property="ButtonArrowType" Value="Right">
                            <Setter TargetName="ScrollChrome" Property="Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph" Value="RightArrow" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 <!-- Other theme specific values here (that is, that are not used by RepeatArrowBotton) -->
    <Style x:Key="UpDownButtonsStyle" TargetType="{x:Type local:UpDownButtons}">
        <Setter Property="Margin" Value="{Binding BorderThickness, ElementName=TextBoxCtrl}"/>
        <Setter Property="BorderThickness" Value="1"/>
    </Style>
    <Style x:Key="TimeCtrlsGridStyle" TargetType="{x:Type Grid}">
        <Setter Property="Margin" Value="{Binding ElementName=TextBoxCtrl, 
                                Path=BorderThickness,
                                Converter={StaticResource ThicknessToMarginConverter},
                                ConverterParameter=true}"/>
    </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