Hey Guys!
WPF gives us DatePicker but it doesn’t give us TimePicker. I tried to create a very simple TimePicker user control.
And the bumper offer is that it is free. Use it wherever you want. J
Hope this will help you a lot.
XAML Code:
<UserControl x:Class="Restaurant.Reservations.UserControls.ucDateTimeUpDown" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid> <Border BorderBrush="Black" BorderThickness=".25" /> <StackPanel Orientation="Horizontal"> <TextBlock x:Name="AddHoursTextBox" MinWidth="20" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding DisplayTimeHours, Mode=OneWay}" TextAlignment="Center" /> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical"> <Button x:Name="HourUpButton" Click="HourUpButton_OnClick"> <Button.Template> <ControlTemplate TargetType="Button"> <Border BorderBrush="Black" BorderThickness=".25"> <Viewbox Width="10" Height="10"> <Image Source="{StaticResource UpImage}" /> </Viewbox> </Border> </ControlTemplate> </Button.Template> </Button> <Button x:Name="HourDownButton" Margin="0,-1,0,0" Click="HourDownButton_OnClick"> <Button.Template> <ControlTemplate TargetType="Button"> <Border BorderBrush="Black" BorderThickness=".25"> <Viewbox Width="10" Height="10"> <Image Source="{StaticResource DownImage}" /> </Viewbox> </Border> </ControlTemplate> </Button.Template> </Button> </StackPanel> <TextBlock Margin="3,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Text="h." /> <TextBlock Margin="3,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Text=":" TextAlignment="Center" /> <TextBlock x:Name="AddMinutesTextBox" MinWidth="20" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding DisplayTimeMinutes, Mode=OneWay}" TextAlignment="Center" /> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical"> <Button x:Name="MinutesUpButton" Click="MinutesUpButton_OnClick"> <Button.Template> <ControlTemplate TargetType="Button"> <Border BorderBrush="Black" BorderThickness=".25"> <Viewbox Width="10" Height="10"> <Image Source="{StaticResource UpImage}" /> </Viewbox> </Border> </ControlTemplate> </Button.Template> </Button> <Button x:Name="MinutesDownButton" Margin="0,-1,0,0" Click="MinutesDownButton_OnClick"> <Button.Template> <ControlTemplate TargetType="Button"> <Border BorderBrush="Black" BorderThickness="0.25"> <Viewbox Width="10" Height="10"> <Image Source="{StaticResource DownImage}" /> </Viewbox> </Border> </ControlTemplate> </Button.Template> </Button> </StackPanel> <TextBlock Margin="3,0,3,0" HorizontalAlignment="Center" VerticalAlignment="Center" Text="m." /> <ComboBox x:Name="AmPmComboBox" MinWidth="45" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness=".25" ItemsSource="{Binding AmPmTypes}" SelectedItem="{Binding DisplayAmPm}" /> </StackPanel> </Grid> </UserControl> |
Code behind:
using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Windows; using System.Windows.Controls; namespace Restaurant.Reservations.UserControls { /// <summary> /// Interaction logic for ucDateTimeUpDown.xaml /// </summary> public partial class ucDateTimeUpDown : UserControl, INotifyPropertyChanged { #region Private Member variable private DateTime _currentTime = DateTime.UtcNow; private bool _adHours; private bool _addMinutes; private ObservableCollection<string> _amPmTypes = new ObservableCollection<string>(); private string _displayAmPm;
|
Comments
Post a Comment