Reputation: 93
Here i used WPF date picker without any style or control template. When i goes to previous month and comes back to same month, i seen some other day is in Enable state. And also i tried some other control template from msdn but issue is still exists.Here i attached screenshot for reference.Tool Used VS2010
Steps to Reproduce:
1.Today Date '4' is highlighted in December Month.
2.Go back to October Month and come back to December month u can able to see '8' is enable state before that it is in disable state.
Upvotes: 3
Views: 496
Reputation: 4885
The problem exists in the default style of CalendarDayButton. (You can get it by right clicking on WPF Designer and choose Edit Additional templates->CalendarDayButtonStyle) There is a VisualStateGroup called ActiveStates in this style. If you look at the Active State, it is empty.
<VisualStateGroup x:Name="ActiveStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Active" />
<VisualState x:Name="Inactive">
<Storyboard>
<ColorAnimation Duration="0"
To="#FF777777"
Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)"
Storyboard.TargetName="NormalText" />
</Storyboard>
</VisualState>
</VisualStateGroup>
So when you change the month to previous and come back, the date slot, which acted for Today date previously, has to change its state from Today State to Active State. Since the active state is empty, the Foreground property will fallback to the one which applied directly to the element, which is dark color (Black).
<ContentPresenter x:Name="NormalText"
TextElement.Foreground="#FF333333"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="5,1,5,1"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
This is the reason, the particular slot appears to be dark, even though it is next month. Now the solution is to add a valid storyboard to Active state (target to dark color), instead of leave it empty. And change the default foreground color applied to the ContentPresenter to light color. Now it will work good. I provided the download link to get the bug free style.
Download CalendarDayButtonStyle
<Calendar CalendarDayButtonStyle="{DynamicResource CalendarDayButtonStyle}" />
Upvotes: 2