WPF: DateTime date picker issue

Here I've used a WPF date picker with no style or control template. When I go to the previous month and return the same month, I saw that some other day is in the On state . And also I tried some other control pattern from msdn but the problem still exists. Here I have attached screenshot for reference.Tool Used by VS2010

Steps to reproduce:

1.Delivery date "4" is highlighted in the month of December.

2. Return to the month of October and return to the month of December. You can see that "8" is the enable state before it is in the disabled state.

enter image description here

+3


source to share


1 answer


The problem exists in the default CalendarDayButton style. (You can get it by right clicking on WPF Designer and choosing Edit Additional templates-> CalendarDayButtonStyle). This style has a VisualStateGroup named ActiveStates . 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>

      

Therefore, when you change the month to the previous one and return, the date slot that was in effect for the "Today" date earlier should change its state from Today state to Active State. Since the active state is empty, the Foreground property will revert to the one that applies directly to the element that is dark (black).

<ContentPresenter x:Name="NormalText"
                TextElement.Foreground="#FF333333"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                Margin="5,1,5,1"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

      



It is for this reason that this particular slot appears to be dark even though it is next month. The solution now is to add the actual storyboard to the Active state (target to dark) rather than leaving it blank. And change the default foreground color applied to the ContentPresenter to a lighter color. Everything will be fine now. I have provided a download link to get the error free style.

Download CalendarDayButtonStyle

<Calendar CalendarDayButtonStyle="{DynamicResource CalendarDayButtonStyle}" />

      

+2


source







All Articles