Click here to Skip to main content
15,885,244 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.3K   3.4K   16  
User controls for entering either a time or a number within a range.
<UserControl x:Class="UpDownCtrls.NumericUpDown"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:local="clr-namespace:UpDownCtrls"
             x:Name="Root"
             d:DesignHeight="23" d:DesignWidth="120"
             MinWidth="23"       
             Loaded="Root_Loaded"
             IsEnabledChanged="Root_IsEnabledChanged">
    <Grid>
        <TextBox Name="TextBoxCtrl" VerticalAlignment="Stretch" Padding="2,2,18,3" 
                IsEnabled="{Binding IsEnabled, ElementName=Root}"               
                Foreground="{Binding Foreground, ElementName=Root}" 
                Height="{Binding ActualHeight, ElementName=Root}"
                Width="{Binding ActualWidth, ElementName=Root}"
                VerticalContentAlignment="{Binding VerticalContentAlignment, ElementName=Root}"
                HorizontalContentAlignment="{Binding  HorizontalContentAlignment, ElementName=Root}"              
                TextAlignment="{Binding TextAlignment, ElementName=Root}"              
                PreviewKeyDown="TextBoxCtrl_PreviewKeyDown"
                PreviewTextInput="TextBoxCtrl_PreviewTextInput"
                PreviewDragOver="TextBoxCtrl_PreviewDragOver"
                PreviewDrop="TextBoxCtrl_PreviewDrop"
                PreviewQueryContinueDrag="TextBoxCtrl_PreviewQueryContinueDrag"
                PreviewMouseWheel="TextBoxCtrl_PreviewMouseWheel"
                LostKeyboardFocus="TextBoxCtrl_LostKeyboardFocus">
            <TextBox.CommandBindings>
                <CommandBinding Command="Cut" CanExecute="Command_Cut_CanExecute" Executed="CommandBinding_CutExecuted"/>
                <CommandBinding Command="Paste" CanExecute="Command_Paste_CanExecute" Executed="CommandBinding_PasteExecuted"/>
            </TextBox.CommandBindings>
        </TextBox>
        <local:UpDownButtons x:Name="UpDown" HorizontalAlignment="Right" 
                Style="{DynamicResource ResourceKey=UpDownButtonsStyle}" 
                VerticalAlignment="Stretch" IsEnabled="{Binding IsEnabled, ElementName=Root}" 
                UpClick="UpDown_UpClick" DownClick="UpDown_DownClick"/>
    </Grid>
</UserControl>

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