2

我使用 WPF 工具包创建了一个 12 个月的日历。我花了一段时间才达到这一点,日历是透明的,文本前景看起来正确。

当我更改 CalendarDayButtonStyle 的样式时,我得到了正确的前景色,但我完全失去了我选择的日期,我不确定缺少什么或不正确。

下面是 XAML

<toolkit:Calendar CalendarItemStyle="{DynamicResource calItemStyle}" CalendarDayButtonStyle="{DynamicResource styleCalDayBtn}" Name="calJan" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Center" VerticalAlignment="Center" MouseDoubleClick="DateSelect_Jan_DoubleClick" SelectedDatesChanged="calJan_SelectDateChanged" SelectionMode="MultipleRange" />

这是 styleCalDayBtn。在这一点上,我需要解决的只是让我选择的日子再次突出显示。我不知道缺少什么,因为我已经尝试了所有内容。

谢谢

<Style x:Key="styleCalDayBtn" TargetType="{x:Type primitives:CalendarDayButton}"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:assembly="http://schemas.microsoft.com/wpf/2008/toolkit" 
         xmlns:s="clr-namespace:System;assembly=mscorlib" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Setter Property="TextElement.FontFamily"  Value="/MyLifeJournal;component/Resources/Font/#Dutch823 BT" />
    <Setter Property="TextElement.Foreground" Value="#FFAA4900" />
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type assembly:CalendarDayButton}">
                <Grid>
                    <Rectangle x:Name="SelectedBackground" RadiusX="1" RadiusY="1" Opacity="0" Fill="BurlyWood" />
                    <Rectangle x:Name="HighlightBackground" RadiusX="1" RadiusY="1" Opacity="0" Fill="White"/>
                    <ContentPresenter
                            x:Name="NormalText"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="5,1,5,1">
                        <TextElement.Foreground>
                            <SolidColorBrush Color="#FFAA4900" />
                        </TextElement.Foreground>
                    </ContentPresenter>
                    <VisualStateManager.VisualStateGroups>
                        <!-- Common States -->
                        <VisualStateGroup Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="Normal" />
                            <VisualState Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="HighlightBackground" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" />
                                    <!--<DoubleAnimation Storyboard.TargetName="NormalText" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" />-->
                                    <!--<ColorAnimation Duration="1" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="Blue"></ColorAnimation>-->
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Pressed">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="HighlightBackground" Storyboard.TargetProperty="Opacity" To="0.5" Duration="0" />
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Disabled">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="HighlightBackground" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                                    <DoubleAnimation Storyboard.TargetName="NormalText" Storyboard.TargetProperty="Opacity" To=".35" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="SelectionStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="Unselected" >
                                <Storyboard>
                                    <!-- <DoubleAnimation Storyboard.TargetName="SelectedBackground" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" /> -->

                                    <!-- <ColorAnimation Duration="0" Storyboard.TargetName="SelectedBackground" Storyboard.TargetProperty="(TextElement.Background).(SolidColorBrush.Color)" To="Blue"></ColorAnimation> -->
                                    <!-- <ColorAnimation Duration="0" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="Blue"></ColorAnimation>-->
                                    <!-- <ColorAnimation Duration="0" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"></ColorAnimation>-->
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Selected">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="SelectedBackground" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" />
                                    <!--<ColorAnimation Duration="0" Storyboard.TargetName="SelectedBackground" Storyboard.TargetProperty="TextElement.Background" To="Blue"></ColorAnimation>
                                    <ColorAnimation Duration="0" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="Black"></ColorAnimation>-->
                                    <!--<ColorAnimation Duration="0" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"></ColorAnimation>-->
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>

                        <VisualStateGroup Name="CalendarButtonFocusStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="CalendarButtonFocused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DayButtonFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="CalendarButtonUnfocused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DayButtonFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Collapsed</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>

                        <VisualStateGroup Name="ActiveStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="Active" />
                            <VisualState Name="Inactive">
                                <Storyboard>
                                    <ColorAnimation Duration="0" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="SkyBlue"></ColorAnimation>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="DayStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="RegularDay">

                            </VisualState>
                            <VisualState Name="Today">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="TodayBackground" Storyboard.TargetProperty="Opacity" To=".5" Duration="0" />
                                    <ColorAnimation Duration="0" Storyboard.TargetName="NormalText" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" To="Purple"></ColorAnimation>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="BlackoutDayStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="NormalDay" />
                            <VisualState Name="BlackoutDay">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" Storyboard.TargetName="Blackout" Storyboard.TargetProperty="Opacity" To=".2"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>

                    </VisualStateManager.VisualStateGroups>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
4

0 回答 0