Skip to content

Commit

Permalink
fix: #4466 collapse colon between hours and minute of timepicker if h…
Browse files Browse the repository at this point in the history
…ours collapsed

Add also a new flag enum to show only minute and seconds.
  • Loading branch information
punker76 committed Feb 26, 2024
1 parent 0fd615b commit d432fcc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:markup="clr-namespace:MetroDemo.Markup"
d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
d:DesignHeight="600"
d:DesignWidth="800"
Expand Down Expand Up @@ -159,17 +160,8 @@
Grid.Row="1"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
SelectedItem="{x:Static mah:TimePartVisibility.All}">
<ComboBox.ItemsSource>
<x:Array Type="mah:TimePartVisibility">
<mah:TimePartVisibility>All</mah:TimePartVisibility>
<mah:TimePartVisibility>HourMinute</mah:TimePartVisibility>
<mah:TimePartVisibility>Hour</mah:TimePartVisibility>
<mah:TimePartVisibility>Minute</mah:TimePartVisibility>
<mah:TimePartVisibility>Second</mah:TimePartVisibility>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
ItemsSource="{Binding Source={markup:EnumBindingSource {x:Type mah:TimePartVisibility}}, Mode=OneTime}"
SelectedItem="{x:Static mah:TimePartVisibility.All}" />

<Label Grid.Row="2"
Grid.Column="0"
Expand All @@ -179,17 +171,8 @@
Grid.Row="2"
Grid.Column="1"
Margin="{StaticResource ControlMargin}"
SelectedItem="{x:Static mah:TimePartVisibility.All}">
<ComboBox.ItemsSource>
<x:Array Type="mah:TimePartVisibility">
<mah:TimePartVisibility>All</mah:TimePartVisibility>
<mah:TimePartVisibility>HourMinute</mah:TimePartVisibility>
<mah:TimePartVisibility>Hour</mah:TimePartVisibility>
<mah:TimePartVisibility>Minute</mah:TimePartVisibility>
<mah:TimePartVisibility>Second</mah:TimePartVisibility>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
ItemsSource="{Binding Source={markup:EnumBindingSource {x:Type mah:TimePartVisibility}}, Mode=OneTime}"
SelectedItem="{x:Static mah:TimePartVisibility.All}" />

<Label Grid.Row="3"
Grid.Column="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum TimePartVisibility
Minute = 1 << 2,
Second = 1 << 3,
HourMinute = Hour | Minute,
MinuteSecond = Minute | Second,
All = HourMinute | Second
}
}
29 changes: 23 additions & 6 deletions src/MahApps.Metro/Themes/DateTimePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,20 @@
FontSize="{TemplateBinding FontSize}"
ItemStringFormat="{TemplateBinding HoursItemStringFormat}"
ItemsSource="{TemplateBinding SourceHours}" />
<Label Grid.Column="1"
Content=":"
Visibility="{Binding Path=Visibility, ElementName=PART_MinutePicker}" />
<Label x:Name="PART_HourMinuteColon"
Grid.Column="1"
Visibility="Collapsed"
Content=":" />
<ComboBox x:Name="PART_MinutePicker"
Grid.Column="2"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
ItemStringFormat="{TemplateBinding MinutesItemStringFormat}"
ItemsSource="{TemplateBinding SourceMinutes}" />
<Label Grid.Column="3"
Content=":"
Visibility="{Binding Path=Visibility, ElementName=PART_SecondPicker}" />
<Label x:Name="PART_MinuteSecondColon"
Grid.Column="3"
Visibility="Collapsed"
Content=":" />
<ComboBox x:Name="PART_SecondPicker"
Grid.Column="4"
FontFamily="{TemplateBinding FontFamily}"
Expand Down Expand Up @@ -395,6 +397,21 @@

</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition SourceName="PART_HourPicker" Property="Visibility" Value="Visible" />
<Condition SourceName="PART_MinutePicker" Property="Visibility" Value="Visible" />
</MultiTrigger.Conditions>
<Setter TargetName="PART_HourMinuteColon" Property="Visibility" Value="Visible" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition SourceName="PART_MinutePicker" Property="Visibility" Value="Visible" />
<Condition SourceName="PART_SecondPicker" Property="Visibility" Value="Visible" />
</MultiTrigger.Conditions>
<Setter TargetName="PART_MinuteSecondColon" Property="Visibility" Value="Visible" />
</MultiTrigger>

<Trigger Property="mah:TextBoxHelper.ClearTextButton" Value="True">
<Setter TargetName="PART_ClearText" Property="Command" Value="{x:Static mah:MahAppsCommands.ClearControlCommand}" />
</Trigger>
Expand Down

0 comments on commit d432fcc

Please sign in to comment.