Skip to content

Commit e566730

Browse files
authored
Adding support for floating scale and floating offset on DatePicker and TimePicker. (#957)
1 parent 0d26a5d commit e566730

File tree

2 files changed

+88
-85
lines changed

2 files changed

+88
-85
lines changed

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<wpf:SmartHint x:Name="Hint"
5757
FontSize="{TemplateBinding FontSize}"
5858
UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
59+
FloatingScale="{Binding Path=(wpf:HintAssist.FloatingScale), RelativeSource={RelativeSource TemplatedParent}}"
60+
FloatingOffset="{Binding Path=(wpf:HintAssist.FloatingOffset), RelativeSource={RelativeSource TemplatedParent}}"
5961
Hint="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource TemplatedParent}}"
6062
HintProxy="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:HintProxyFabricConverter.Instance}}"
6163
HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}" />
@@ -167,20 +169,20 @@
167169
Margin="4 0 0 -3"
168170
Grid.Row="0"
169171
Template="{StaticResource DropDownButtonTemplate}" Padding="0"
170-
Height="17" />
172+
Height="17" />
171173
<DatePickerTextBox x:Name="PART_TextBox"
172174
Grid.Column="0"
173175
Focusable="{TemplateBinding Focusable}"
174176
HorizontalContentAlignment="Stretch"
175177
Grid.Row="0"
176178
VerticalContentAlignment="Center"
177179
Style="{DynamicResource MaterialDesignDatePickerTextBox}"
178-
HorizontalAlignment="Stretch" />
179-
<Popup x:Name="PART_Popup" AllowsTransparency="True"
180+
HorizontalAlignment="Stretch" />
181+
<Popup x:Name="PART_Popup" AllowsTransparency="True"
180182
Placement="Custom"
181183
CustomPopupPlacementCallback="{x:Static wpf:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
182184
PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
183-
PopupAnimation="Fade" />
185+
PopupAnimation="Fade" />
184186
</Grid>
185187
</Border>
186188
<wpf:Underline x:Name="Underline" Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}" />

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TimePicker.xaml

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
</ResourceDictionary.MergedDictionaries>
99

1010
<converters:TextFieldHintVisibilityConverter x:Key="TextFieldHintVisibilityConverter" />
11-
12-
<Style x:Key="MaterialDesignTimePicker" TargetType="{x:Type wpf:TimePicker}">
13-
<Setter Property="VerticalAlignment" Value="Top"/>
14-
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
15-
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
16-
<Setter Property="Background" Value="Transparent"/>
17-
<Setter Property="BorderThickness" Value="0 0 0 1"/>
18-
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
11+
12+
<Style x:Key="MaterialDesignTimePicker" TargetType="{x:Type wpf:TimePicker}">
13+
<Setter Property="VerticalAlignment" Value="Top"/>
14+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
15+
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
16+
<Setter Property="Background" Value="Transparent"/>
17+
<Setter Property="BorderThickness" Value="0 0 0 1"/>
18+
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
1919
<Setter Property="IsTabStop" Value="False"/>
2020
<Setter Property="Margin" Value="0 12 0 0" />
2121
<Setter Property="wpf:HintAssist.Hint" Value="Select time" />
22-
<Setter Property="ClockStyle" Value="{DynamicResource MaterialDesignClock}" />
22+
<Setter Property="ClockStyle" Value="{DynamicResource MaterialDesignClock}" />
2323
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
24-
<Setter Property="ClockHostContentControlStyle">
25-
<Setter.Value>
26-
<Style TargetType="{x:Type ContentControl}">
27-
<Style.Setters>
28-
<Setter Property="Template">
29-
<Setter.Value>
24+
<Setter Property="ClockHostContentControlStyle">
25+
<Setter.Value>
26+
<Style TargetType="{x:Type ContentControl}">
27+
<Style.Setters>
28+
<Setter Property="Template">
29+
<Setter.Value>
3030
<ControlTemplate TargetType="{x:Type ContentControl}">
3131
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
3232
<Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
@@ -35,26 +35,27 @@
3535
</AdornerDecorator>
3636
</ControlTemplate>
3737
</Setter.Value>
38-
</Setter>
39-
</Style.Setters>
40-
</Style>
41-
</Setter.Value>
42-
</Setter>
43-
<Setter Property="Template">
44-
<Setter.Value>
45-
<ControlTemplate TargetType="{x:Type wpf:TimePicker}">
46-
<ControlTemplate.Resources>
47-
<ControlTemplate x:Key="TextBoxTemplate" TargetType="{x:Type TextBox}">
48-
<Grid>
49-
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"
50-
/>
38+
</Setter>
39+
</Style.Setters>
40+
</Style>
41+
</Setter.Value>
42+
</Setter>
43+
<Setter Property="Template">
44+
<Setter.Value>
45+
<ControlTemplate TargetType="{x:Type wpf:TimePicker}">
46+
<ControlTemplate.Resources>
47+
<ControlTemplate x:Key="TextBoxTemplate" TargetType="{x:Type TextBox}">
48+
<Grid>
49+
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
5150
<wpf:SmartHint x:Name="Hint"
5251
FontSize="{TemplateBinding FontSize}"
5352
UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
53+
FloatingScale="{Binding Path=(wpf:HintAssist.FloatingScale), RelativeSource={RelativeSource TemplatedParent}}"
54+
FloatingOffset="{Binding Path=(wpf:HintAssist.FloatingOffset), RelativeSource={RelativeSource TemplatedParent}}"
5455
Hint="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource TemplatedParent}}"
5556
HintProxy="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:HintProxyFabricConverter.Instance}}"
5657
HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}"/>
57-
</Grid>
58+
</Grid>
5859
<ControlTemplate.Triggers>
5960
<MultiTrigger>
6061
<MultiTrigger.Conditions>
@@ -66,56 +67,56 @@
6667
</MultiTrigger>
6768
</ControlTemplate.Triggers>
6869
</ControlTemplate>
69-
<ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
70-
<Grid Background="Transparent">
71-
<VisualStateManager.VisualStateGroups>
72-
<VisualStateGroup x:Name="CommonStates">
73-
<VisualStateGroup.Transitions>
74-
<VisualTransition GeneratedDuration="0"/>
75-
<VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
76-
<VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/>
77-
</VisualStateGroup.Transitions>
78-
<VisualState x:Name="Normal"/>
79-
<VisualState x:Name="MouseOver"/>
80-
<VisualState x:Name="Pressed"/>
81-
<VisualState x:Name="Disabled"/>
82-
</VisualStateGroup>
83-
</VisualStateManager.VisualStateGroups>
84-
<Viewbox>
85-
<Canvas Width="24" Height="24">
86-
<Path Data="M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2M12.5,7V12.25L17,14.92L16.25,16.15L11,13V7H12.5Z" Fill="{TemplateBinding Foreground}" />
87-
</Canvas>
88-
</Viewbox>
89-
</Grid>
90-
</ControlTemplate>
91-
</ControlTemplate.Resources>
70+
<ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
71+
<Grid Background="Transparent">
72+
<VisualStateManager.VisualStateGroups>
73+
<VisualStateGroup x:Name="CommonStates">
74+
<VisualStateGroup.Transitions>
75+
<VisualTransition GeneratedDuration="0"/>
76+
<VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
77+
<VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/>
78+
</VisualStateGroup.Transitions>
79+
<VisualState x:Name="Normal"/>
80+
<VisualState x:Name="MouseOver"/>
81+
<VisualState x:Name="Pressed"/>
82+
<VisualState x:Name="Disabled"/>
83+
</VisualStateGroup>
84+
</VisualStateManager.VisualStateGroups>
85+
<Viewbox>
86+
<Canvas Width="24" Height="24">
87+
<Path Data="M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2M12.5,7V12.25L17,14.92L16.25,16.15L11,13V7H12.5Z" Fill="{TemplateBinding Foreground}" />
88+
</Canvas>
89+
</Viewbox>
90+
</Grid>
91+
</ControlTemplate>
92+
</ControlTemplate.Resources>
9293
<Grid x:Name="TemplateRoot">
93-
<Border BorderBrush="{TemplateBinding BorderBrush}"
94+
<Border BorderBrush="{TemplateBinding BorderBrush}"
9495
BorderThickness="{TemplateBinding BorderThickness}"
9596
Background="{TemplateBinding Background}"
9697
x:Name="border"
9798
Padding="0 4 0 4"
9899
SnapsToDevicePixels="True">
99-
<Grid>
100-
<Grid.ColumnDefinitions>
101-
<ColumnDefinition Width="*" />
102-
<ColumnDefinition Width="Auto" />
103-
</Grid.ColumnDefinitions>
104-
<TextBox BorderThickness="0" x:Name="PART_TextBox"
105-
wpf:TextFieldAssist.TextBoxViewMargin=".5 0 0 0"
106-
Margin="0"
107-
Template="{StaticResource TextBoxTemplate}"
108-
/>
109-
<Button Grid.Column="1" Foreground="{TemplateBinding BorderBrush}" Focusable="False" HorizontalAlignment="Right" Margin="4 0 0 -3" Grid.Row="0" Padding="0"
110-
x:Name="PART_Button"
111-
Height="17"
112-
Template="{StaticResource DropDownButtonTemplate}" />
113-
<Popup x:Name="PART_Popup" AllowsTransparency="True"
100+
<Grid>
101+
<Grid.ColumnDefinitions>
102+
<ColumnDefinition Width="*" />
103+
<ColumnDefinition Width="Auto" />
104+
</Grid.ColumnDefinitions>
105+
<TextBox BorderThickness="0" x:Name="PART_TextBox"
106+
wpf:TextFieldAssist.TextBoxViewMargin=".5 0 0 0"
107+
Margin="0"
108+
Template="{StaticResource TextBoxTemplate}"
109+
/>
110+
<Button Grid.Column="1" Foreground="{TemplateBinding BorderBrush}" Focusable="False" HorizontalAlignment="Right" Margin="4 0 0 -3" Grid.Row="0" Padding="0"
111+
x:Name="PART_Button"
112+
Height="17"
113+
Template="{StaticResource DropDownButtonTemplate}" />
114+
<Popup x:Name="PART_Popup" AllowsTransparency="True"
114115
Placement="Custom"
115116
CustomPopupPlacementCallback="{x:Static wpf:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
116117
PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
117-
PopupAnimation="Fade"/>
118-
</Grid>
118+
PopupAnimation="Fade"/>
119+
</Grid>
119120
</Border>
120121
<wpf:Underline x:Name="Underline" Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"/>
121122
</Grid>
@@ -124,21 +125,21 @@
124125
<Setter Property="Opacity" TargetName="TemplateRoot" Value="0.56"/>
125126
</Trigger>
126127
<Trigger Property="IsMouseOver" Value="true">
127-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
128-
</Trigger>
129-
<Trigger Property="IsKeyboardFocusWithin" Value="true">
128+
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
129+
</Trigger>
130+
<Trigger Property="IsKeyboardFocusWithin" Value="true">
130131
<Setter Property="IsActive" TargetName="Underline" Value="True"/>
131-
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
132-
</Trigger>
132+
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryHueMidBrush}"/>
133+
</Trigger>
133134
<Trigger Property="Validation.HasError" Value="true">
134135
<Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/>
135136
<Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}"/>
136-
</Trigger>
137-
</ControlTemplate.Triggers>
138-
</ControlTemplate>
139-
</Setter.Value>
140-
</Setter>
141-
</Style>
137+
</Trigger>
138+
</ControlTemplate.Triggers>
139+
</ControlTemplate>
140+
</Setter.Value>
141+
</Setter>
142+
</Style>
142143

143144

144145
<Style x:Key="MaterialDesignFloatingHintTimePicker" TargetType="{x:Type wpf:TimePicker}" BasedOn="{StaticResource MaterialDesignTimePicker}">

0 commit comments

Comments
 (0)