Reputation: 9081
I have a WPF application, in which I have a datepicker
:
<DatePicker HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding DateP, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" DisplayDateStart="{Binding Source={x:Static sys:DateTime.Now}, Mode=OneTime}"/>
I'd like to change the appearence of dates before the DisplayDateStart
date. Now these dates are hidden
Upvotes: 2
Views: 105
Reputation: 5234
WPF doesn't seem to offer a VisualState for these hidden items. However, you can use a trigger on the CalendarDayButton style's ControlTemplate. In the below example I'm collapsing the hidden date items to avoid the unnecessary whitespace.
<Style TargetType="CalendarDayButton" x:Key="CalendarDayButtonStyle">
<Setter Property="MinWidth" Value="5" />
<Setter Property="MinHeight" Value="0" />
<Setter Property="FontSize" Value="10" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CalendarDayButton">
<Grid x:Name="dayButtonContainer">
// ... your presentation display
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Visibility" Value="Hidden">
<Setter TargetName="dayButtonContainer" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="Visibility" Value="Visible">
<Setter TargetName="dayButtonContainer" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Upvotes: 0
Reputation: 333
Instead of hiding the dates using the DisplayDateStart
you can specify the BlackoutDates
so that the dates will be displayed but not selectable. This way you can style your DatePicker
and apply one you prefer for non selectable dates (it is crossed out in default style).
More on the topic: MSDN: DatePicker.BlackoutDates Property
Upvotes: 1