Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Allow DateTimePicker to choose to use Clock or ListClock #1299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Shared/HandyControl_Shared/Controls/Input/DateTimePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Media;
using System.Windows.Threading;
using HandyControl.Data;
using HandyControl.Data.Enum;
using HandyControl.Interactivity;

namespace HandyControl.Controls;
Expand Down Expand Up @@ -92,6 +93,24 @@ public DateTimePicker()

#region Public Properties

public static readonly DependencyProperty ClockTypeProperty = DependencyProperty.Register(
nameof(ClockType),
typeof(ClockType),
typeof(DateTimePicker),
new PropertyMetadata(ClockType.Clock, ClockStyleChanged));

private static void ClockStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dp = (DateTimePicker) d;
dp._calendarWithClock.ClockType = (ClockType) e.NewValue;
}

public ClockType ClockType
{
get { return (ClockType) GetValue(ClockTypeProperty); }
set { SetValue(ClockTypeProperty, value); }
}

public static readonly DependencyProperty DateTimeFormatProperty = DependencyProperty.Register(
nameof(DateTimeFormat), typeof(string), typeof(DateTimePicker), new PropertyMetadata("yyyy-MM-dd HH:mm:ss"));

Expand Down
70 changes: 62 additions & 8 deletions src/Shared/HandyControl_Shared/Controls/Time/CalendarWithClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Windows.Input;
using System.Windows.Media;
using HandyControl.Data;
using HandyControl.Data.Enum;
using HandyControl.Tools;

namespace HandyControl.Controls;

Expand All @@ -29,7 +31,7 @@ public class CalendarWithClock : Control

private ContentPresenter _calendarPresenter;

private Clock _clock;
private ClockBase _clock;

private Calendar _calendar;

Expand Down Expand Up @@ -72,6 +74,25 @@ public CalendarWithClock()

#region Public Properties

public static readonly DependencyProperty ClockTypeProperty = DependencyProperty.Register(
nameof(ClockType),
typeof(ClockType),
typeof(CalendarWithClock),
new PropertyMetadata(ClockType.Clock, ClockStyleChanged));

private static void ClockStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dp = (CalendarWithClock) d;
dp.ClockType = (ClockType) e.NewValue;
dp.InitClock();
}

public ClockType ClockType
{
get { return (ClockType) GetValue(ClockTypeProperty); }
set { SetValue(ClockTypeProperty, value); }
}

public static readonly DependencyProperty DateTimeFormatProperty = DependencyProperty.Register(
nameof(DateTimeFormat), typeof(string), typeof(CalendarWithClock), new PropertyMetadata("yyyy-MM-dd HH:mm:ss"));

Expand Down Expand Up @@ -214,13 +235,7 @@ private void ButtonConfirm_OnClick(object sender, RoutedEventArgs e)

private void InitCalendarAndClock()
{
_clock = new Clock
{
BorderThickness = new Thickness(),
Background = Brushes.Transparent
};
TitleElement.SetBackground(_clock, Brushes.Transparent);
_clock.DisplayTimeChanged += Clock_DisplayTimeChanged;
InitClock();

_calendar = new Calendar
{
Expand All @@ -232,6 +247,45 @@ private void InitCalendarAndClock()
_calendar.SelectedDatesChanged += Calendar_SelectedDatesChanged;
}

private void InitClock()
{
if (_clock != null)
{
_clock.DisplayTimeChanged -= Clock_DisplayTimeChanged;
}

switch (ClockType)
{
case ClockType.Clock:
_clock = new Clock
{
BorderThickness = new Thickness(),
Background = Brushes.Transparent
};
break;

case ClockType.ListClock:
_clock = new ListClock
{
BorderThickness = new Thickness(),
Background = Brushes.Transparent,
Style = ResourceHelper.GetResourceInternal<Style>(ResourceToken.ListClockForCalendarWithClockStyle)
};
break;

default:
_clock = new Clock
{
BorderThickness = new Thickness(),
Background = Brushes.Transparent
};
break;
}

TitleElement.SetBackground(_clock, Brushes.Transparent);
_clock.DisplayTimeChanged += Clock_DisplayTimeChanged;
}

private void Calendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
Mouse.Capture(null);
Expand Down
8 changes: 8 additions & 0 deletions src/Shared/HandyControl_Shared/Data/Enum/ClockType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace HandyControl.Data.Enum
{
public enum ClockType
{
Clock,
ListClock
}
}
2 changes: 2 additions & 0 deletions src/Shared/HandyControl_Shared/Data/ResourceToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,7 @@ public class ResourceToken

internal const string ComboBoxItemCapsuleVerticalLast = nameof(ComboBoxItemCapsuleVerticalLast);

internal const string ListClockForCalendarWithClockStyle = nameof(ListClockForCalendarWithClockStyle);

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Tag\TagContainer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Text\HighlightTextBlock.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Text\SimpleText.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ClockType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\GrowlShowMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\LinearLayout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\EventToCommand.cs" />
Expand Down
38 changes: 37 additions & 1 deletion src/Shared/HandyControl_Shared/Themes/Styles/Clock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,41 @@
</Style>

<Style TargetType="hc:ListClock" BasedOn="{StaticResource ListClockBaseStyle}"/>


<Style x:Key="ListClockForCalendarWithClockStyle" BasedOn="{StaticResource ListClockBaseStyle}" TargetType="hc:ListClock">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:ListClock">
<hc:SimplePanel Margin="0,4,0,8" HorizontalAlignment="Center" VerticalAlignment="Top">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}" Effect="{StaticResource EffectShadow2}" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Border Height="50">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="White" Text="{Binding DisplayTime, RelativeSource={RelativeSource TemplatedParent}, StringFormat={}{0:HH:mm:ss}}" TextAlignment="Center" />
</Border>
<Grid Grid.Row="1" Width="210" Margin="0,20">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox x:Name="PART_HourList" Padding="0" hc:BorderElement.CornerRadius="0" Style="{StaticResource ClockListBoxStyle}" />
<ListBox x:Name="PART_MinuteList" Grid.Row="0" Grid.Column="1" Padding="0" hc:BorderElement.CornerRadius="0" BorderThickness="1,0" Style="{StaticResource ClockListBoxStyle}" />
<ListBox x:Name="PART_SecondList" Grid.Row="0" Grid.Column="2" Padding="0" hc:BorderElement.CornerRadius="0" Style="{StaticResource ClockListBoxStyle}" />
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Height="1" VerticalAlignment="Bottom" Background="{DynamicResource BorderBrush}" Visibility="{Binding Visibility, ElementName=PART_ButtonConfirm}" />
<Button Name="PART_ButtonConfirm" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,10" HorizontalAlignment="Center" Background="Transparent" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Foreground="{DynamicResource PrimaryBrush}" Style="{StaticResource ButtonCustom}" Visibility="Collapsed" />
</Grid>
</Grid>
</hc:SimplePanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
36 changes: 36 additions & 0 deletions src/Shared/HandyControl_Shared/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12862,6 +12862,42 @@
</Setter>
</Style>
<Style TargetType="hc:ListClock" BasedOn="{StaticResource ListClockBaseStyle}" />
<Style x:Key="ListClockForCalendarWithClockStyle" BasedOn="{StaticResource ListClockBaseStyle}" TargetType="hc:ListClock">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:ListClock">
<hc:SimplePanel Margin="0,4,0,8" HorizontalAlignment="Center" VerticalAlignment="Top">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}" Effect="{StaticResource EffectShadow2}" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Border Height="50">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="White" Text="{Binding DisplayTime, RelativeSource={RelativeSource TemplatedParent}, StringFormat={}{0:HH:mm:ss}}" TextAlignment="Center" />
</Border>
<Grid Grid.Row="1" Width="210" Margin="0,20">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox x:Name="PART_HourList" Padding="0" hc:BorderElement.CornerRadius="0" Style="{StaticResource ClockListBoxStyle}" />
<ListBox x:Name="PART_MinuteList" Grid.Row="0" Grid.Column="1" Padding="0" hc:BorderElement.CornerRadius="0" BorderThickness="1,0" Style="{StaticResource ClockListBoxStyle}" />
<ListBox x:Name="PART_SecondList" Grid.Row="0" Grid.Column="2" Padding="0" hc:BorderElement.CornerRadius="0" Style="{StaticResource ClockListBoxStyle}" />
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Height="1" VerticalAlignment="Bottom" Background="{DynamicResource BorderBrush}" Visibility="{Binding Visibility, ElementName=PART_ButtonConfirm}" />
<Button Name="PART_ButtonConfirm" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,10" HorizontalAlignment="Center" Background="Transparent" Content="{ex:Lang Key={x:Static langs:LangKeys.Confirm}}" Foreground="{DynamicResource PrimaryBrush}" Style="{StaticResource ButtonCustom}" Visibility="Collapsed" />
</Grid>
</Grid>
</hc:SimplePanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource ColorPickerBaseStyle}" TargetType="hc:ColorPicker" />
<Style BasedOn="{StaticResource ContextMenuBaseStyle}" TargetType="ContextMenu" />
<Style x:Key="ContextMenu.Small" BasedOn="{StaticResource ContextMenuBaseStyle}" TargetType="ContextMenu">
Expand Down