Skip to content

Commit c0fb4f7

Browse files
committed
Merge pull request #142 from jdf3/calendar-blackout-md
Add blackout styles to calendar. Thankyou @jdf3 and welcome to the contributors list!
2 parents faa0f97 + 8e2766d commit c0fb4f7

File tree

3 files changed

+82
-65
lines changed

3 files changed

+82
-65
lines changed

MainDemo.Wpf/Pickers.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
<ColumnDefinition Width="Auto" />
2020
</Grid.ColumnDefinitions>
2121
<TextBlock Grid.ColumnSpan="3">Classic WPF DatePicker control with Material Design theme, and new TimePicker control:</TextBlock>
22-
<DatePicker Grid.Row="1" Grid.Column="0" Width="100" HorizontalAlignment="Left" Margin="0 16 0 0"
23-
materialDesign:TextFieldAssist.Hint="Pick Date"/>
22+
<StackPanel Grid.Row="1" Grid.Column="0">
23+
<DatePicker Width="100" HorizontalAlignment="Left" Margin="0 16 0 0" materialDesign:TextFieldAssist.Hint="Pick Date" />
24+
<DatePicker x:Name="FutureDatePicker" Width="100" HorizontalAlignment="Left" Margin="0 16 0 0" materialDesign:TextFieldAssist.Hint="Future Date" />
25+
</StackPanel>
2426
<materialDesign:TimePicker Grid.Row="1" Grid.Column="1" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 16 0 0"
2527
materialDesign:TextFieldAssist.Hint="Custom hint" />
2628
<materialDesign:TimePicker Grid.Row="1" Grid.Column="2" Is24Hours="True" x:Name="PresetTimePicker" VerticalAlignment="Top" Width="100" HorizontalAlignment="Left" Margin="0 16 0 0" />

MainDemo.Wpf/Pickers.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public partial class Pickers : UserControl
2424
public Pickers()
2525
{
2626
InitializeComponent();
27+
FutureDatePicker.BlackoutDates.AddDatesInPast();
2728
}
2829

2930
public void CalendarDialogOpenedEventHandler(object sender, DialogOpenedEventArgs eventArgs)

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Calendar.xaml

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Setter Property="MinWidth" Value="5"/>
88
<Setter Property="MinHeight" Value="5"/>
99
<Setter Property="FontSize" Value="12"/>
10+
<Setter Property="Cursor" Value="Hand"/>
1011
<Setter Property="Background" Value="Transparent"/>
1112
<Setter Property="Margin" Value="2"/>
1213
<Setter Property="Width" Value="48" />
@@ -86,66 +87,51 @@
8687
<VisualTransition GeneratedDuration="0"/>
8788
</VisualStateGroup.Transitions>
8889
<VisualState x:Name="Active"/>
89-
<VisualState x:Name="Inactive">
90-
<Storyboard>
91-
<!--ColorAnimation Duration="0" To="#FF777777" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="NormalText"/-->
92-
</Storyboard>
93-
</VisualState>
94-
</VisualStateGroup>
95-
<VisualStateGroup x:Name="DayStates">
96-
<VisualStateGroup.Transitions>
97-
<VisualTransition GeneratedDuration="0"/>
98-
</VisualStateGroup.Transitions>
99-
<VisualState x:Name="RegularDay"/>
100-
<VisualState x:Name="Today">
101-
<Storyboard>
102-
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TodayBackground"/>
103-
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground)" Storyboard.TargetName="NormalText">
104-
<DiscreteObjectKeyFrame Value="{DynamicResource PrimaryHueLightForegroundBrush}" KeyTime="0" />
105-
</ObjectAnimationUsingKeyFrames>
106-
</Storyboard>
107-
</VisualState>
108-
</VisualStateGroup>
109-
<VisualStateGroup x:Name="BlackoutDayStates">
110-
<VisualStateGroup.Transitions>
111-
<VisualTransition GeneratedDuration="0"/>
112-
</VisualStateGroup.Transitions>
113-
<VisualState x:Name="NormalDay"/>
114-
<VisualState x:Name="BlackoutDay">
115-
<Storyboard>
116-
<DoubleAnimation Duration="0" To=".2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Blackout"/>
117-
</Storyboard>
118-
</VisualState>
90+
<VisualState x:Name="Inactive" />
11991
</VisualStateGroup>
12092
</VisualStateManager.VisualStateGroups>
121-
<Ellipse x:Name="TodayBackground" Fill="{DynamicResource PrimaryHueLightBrush}" Opacity="0" />
122-
<Ellipse x:Name="SelectedBackground" Fill="{DynamicResource PrimaryHueMidBrush}" Opacity="0" />
123-
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
124-
<Ellipse x:Name="HighlightBackground" Fill="{DynamicResource PrimaryHueDarkBrush}" Opacity="0" />
93+
<Ellipse x:Name="TodayBackground"
94+
Fill="{DynamicResource PrimaryHueLightBrush}"
95+
Opacity="0" />
96+
<Ellipse x:Name="SelectedBackground"
97+
Fill="{DynamicResource PrimaryHueMidBrush}"
98+
Opacity="0" />
99+
<Border BorderBrush="{TemplateBinding BorderBrush}"
100+
BorderThickness="{TemplateBinding BorderThickness}"
101+
Background="{TemplateBinding Background}" />
102+
<Ellipse x:Name="HighlightBackground"
103+
Fill="{DynamicResource PrimaryHueDarkBrush}"
104+
Opacity="0" />
125105
<ContentPresenter x:Name="NormalText"
126106
TextElement.Foreground="{TemplateBinding Foreground}"
127107
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
128108
Margin="5,1,5,1"
129109
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
130-
<Path x:Name="Blackout"
131-
Fill="#FF000000"
132-
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
133-
Margin="3"
134-
Opacity="0"
135-
RenderTransformOrigin="0.5,0.5"
136-
Stretch="Fill"
137-
Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z" />
138-
<Ellipse x:Name="DayButtonFocusVisual" Stroke="{DynamicResource PrimaryHueDarkBrush}" Opacity="0" Visibility="Collapsed" StrokeThickness="1"/>
110+
<Ellipse x:Name="DayButtonFocusVisual"
111+
Stroke="{DynamicResource PrimaryHueDarkBrush}"
112+
Opacity="0"
113+
Visibility="Collapsed"
114+
StrokeThickness="1" />
139115
</Grid>
140116
</ControlTemplate>
141117
</Setter.Value>
142118
</Setter>
119+
<Style.Triggers>
120+
<Trigger Property="IsInactive"
121+
Value="True">
122+
<Setter Property="MinHeight"
123+
Value="0" />
124+
<Setter Property="MaxHeight"
125+
Value="0" />
126+
</Trigger>
127+
</Style.Triggers>
143128
</Style>
144129

145130
<Style x:Key="MaterialDesignCalendarDayButton" TargetType="{x:Type CalendarDayButton}">
146131
<Setter Property="MinWidth" Value="5"/>
147132
<Setter Property="MinHeight" Value="5"/>
148133
<Setter Property="FontSize" Value="12"/>
134+
<Setter Property="Cursor" Value="Hand" />
149135
<Setter Property="Margin" Value="2"/>
150136
<Setter Property="Width" Value="34" />
151137
<Setter Property="Height" Value="34" />
@@ -224,11 +210,7 @@
224210
<VisualTransition GeneratedDuration="0"/>
225211
</VisualStateGroup.Transitions>
226212
<VisualState x:Name="Active"/>
227-
<VisualState x:Name="Inactive">
228-
<Storyboard>
229-
<DoubleAnimation Duration="0" To="0.2" Storyboard.TargetProperty="Opacity"/>
230-
</Storyboard>
231-
</VisualState>
213+
<VisualState x:Name="Inactive"/>
232214
</VisualStateGroup>
233215
<VisualStateGroup x:Name="DayStates">
234216
<VisualStateGroup.Transitions>
@@ -251,29 +233,61 @@
251233
<VisualState x:Name="NormalDay"/>
252234
<VisualState x:Name="BlackoutDay">
253235
<Storyboard>
254-
<DoubleAnimation Duration="0" To=".2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Blackout"/>
236+
<DoubleAnimation Duration="0"
237+
To="0"
238+
Storyboard.TargetProperty="Opacity"
239+
Storyboard.TargetName="HighlightingBorder"/>
240+
<DoubleAnimation Duration="0"
241+
To="0.38"
242+
Storyboard.TargetProperty="Opacity"
243+
Storyboard.TargetName="NormalText" />
255244
</Storyboard>
256245
</VisualState>
257246
</VisualStateGroup>
258247
</VisualStateManager.VisualStateGroups>
259-
<Ellipse x:Name="TodayBackground" Fill="{DynamicResource PrimaryHueLightBrush}" Opacity="0" />
260-
<Ellipse x:Name="SelectedBackground" Fill="{DynamicResource PrimaryHueMidBrush}" Opacity="0" />
261-
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
262-
<Ellipse x:Name="HighlightBackground" Fill="{DynamicResource PrimaryHueDarkBrush}" Opacity="0" />
263-
<ContentPresenter x:Name="NormalText" TextElement.Foreground="{TemplateBinding Foreground}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="5,1,5,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
264-
<Path x:Name="Blackout"
265-
Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z"
266-
Fill="#FF000000"
267-
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
268-
Margin="3"
269-
Opacity="0"
270-
RenderTransformOrigin="0.5,0.5"
271-
Stretch="Fill"/>
272-
<Ellipse x:Name="DayButtonFocusVisual" Stroke="{DynamicResource PrimaryHueDarkBrush}" Opacity="0" Visibility="Collapsed" StrokeThickness="1"/>
248+
<Ellipse x:Name="TodayBackground"
249+
Fill="{DynamicResource PrimaryHueLightBrush}"
250+
Opacity="0" />
251+
<Ellipse x:Name="SelectedBackground"
252+
Fill="{DynamicResource PrimaryHueMidBrush}"
253+
Opacity="0" />
254+
<Border BorderBrush="{TemplateBinding BorderBrush}"
255+
BorderThickness="{TemplateBinding BorderThickness}"
256+
Background="{TemplateBinding Background}"/>
257+
<Border x:Name="HighlightingBorder"
258+
Opacity="1">
259+
<Ellipse x:Name="HighlightBackground"
260+
Fill="{DynamicResource PrimaryHueDarkBrush}"
261+
Opacity="0"/>
262+
</Border>
263+
<ContentPresenter x:Name="NormalText"
264+
TextElement.Foreground="{TemplateBinding Foreground}"
265+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
266+
Margin="5,1,5,1"
267+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
268+
<Ellipse x:Name="DayButtonFocusVisual"
269+
Stroke="{DynamicResource PrimaryHueDarkBrush}"
270+
Opacity="0"
271+
Visibility="Collapsed"
272+
StrokeThickness="1"/>
273273
</Grid>
274274
</ControlTemplate>
275275
</Setter.Value>
276276
</Setter>
277+
<Style.Triggers>
278+
<Trigger Property="IsInactive"
279+
Value="True">
280+
<Setter Property="MinHeight"
281+
Value="0" />
282+
<Setter Property="MaxHeight"
283+
Value="0" />
284+
</Trigger>
285+
<Trigger Property="IsBlackedOut"
286+
Value="True">
287+
<Setter Property="Cursor"
288+
Value="No" />
289+
</Trigger>
290+
</Style.Triggers>
277291
</Style>
278292

279293
<Style x:Key="MaterialDesignCalendarItemPortrait" TargetType="{x:Type CalendarItem}">

0 commit comments

Comments
 (0)