Articles in this section
Category / Section

How to customize the background, hover background, and selected background of calendar used in DateTimeEdit ?

2 mins read

 

In DateTimEdit, there is no direct option to customize the background of the calendar. But, you can customize the background of the calendar by editing the calendar style. Here, today background, hover background, and selected background of calendar are customized using calendar style and with help of the brushes (TodayBackgroundBrush, HoverBackgroundBrush, and SelectedBackgroundBrush).

 

The following code sample demonstrates this.

 

XAML:

 

  <Window.Resources>

 

        <SolidColorBrush x:Key="TodayBackgroundBrush" Color="Purple" />

        <SolidColorBrush x:Key="HoverBackgroundBrush" Color="Red" />

        <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Yellow" />

 

        <!--CalendarDayButton-->

 

        <Style TargetType="{x:Type primitives:CalendarDayButton}">

            <Setter Property="Background" Value="White"/>

            <Setter Property="MinWidth" Value="5"/>

            <Setter Property="MinHeight" Value="5"/>

            <Setter Property="FontSize" Value="10"/>

            <Setter Property="HorizontalContentAlignment" Value="Center"/>

            <Setter Property="VerticalContentAlignment" Value="Center"/>

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="{x:Type primitives:CalendarDayButton}">

                        <Grid>

                            <Rectangle x:Name="TodayBackground" RadiusX="1" RadiusY="1" Opacity="0" Fill="#FFAAAAAA"/>

                            <Rectangle x:Name="SelectedBackground" RadiusX="1" RadiusY="1" Opacity="0" Fill="{TemplateBinding Background}"/>

                            <Rectangle x:Name="Background" RadiusX="1" RadiusY="1"  Fill="{TemplateBinding Background}"/>

                            <ContentPresenter

                                x:Name="NormalText"

                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

                                Margin="5,1,5,1">

                                <TextElement.Foreground>

 

                                    <SolidColorBrush x:Name="selectedText" Color="#FF333333"/>

                                </TextElement.Foreground>

                            </ContentPresenter>

                            <Path x:Name="Blackout" Opacity="0" Margin="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" Fill="#FF000000" Stretch="Fill" 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"/>

                            <Rectangle x:Name="DayButtonFocusVisual" Visibility="Collapsed" IsHitTestVisible="false" RadiusX="1" RadiusY="1" Stroke="#FF45D6FA"/>

                        </Grid>

                        <ControlTemplate.Triggers>

                            <Trigger Property="IsMouseOver" Value="True">

                                <!--HoverBackgroundBrush is used to update hover Background-->

                                <Setter Property="Background" Value="{StaticResource HoverBackgroundBrush}"/>

                            </Trigger>

                            <Trigger Property="IsPressed" Value="True">

                                <Setter TargetName="Background" Property="Opacity" Value="0.5"/>

                            </Trigger>

                            <Trigger Property="IsEnabled" Value="False">

                                <Setter TargetName="Background" Property="Opacity" Value="0"/>

                                <Setter TargetName="NormalText" Property="Opacity" Value="0.35"/>

                            </Trigger>

                            <Trigger Value="True" Property="IsSelected">

                                <Setter TargetName="SelectedBackground" Property="Opacity" Value="0.75"/>

                                <!--SelectedBackgroundBrush is used to update Selected Background-->

 

                                <Setter TargetName="Background" Property="Fill" Value="{StaticResource SelectedBackgroundBrush}"/>

                            </Trigger>

                            <Trigger Value="True" Property="IsToday">

                                <Setter TargetName="TodayBackground" Property="Opacity" Value="1"/>

 

                                <!--TodayBackgroundBrush is used to update today Background-->

 

                                <Setter TargetName="Background" Property="Fill" Value="{StaticResource TodayBackgroundBrush}"/>

                                <Setter TargetName="NormalText" Property="TextElement.Foreground" Value="#FFFFFFFF"/>

                            </Trigger>

                            <Trigger Value="True" Property="IsBlackedOut">

                                <Setter TargetName="Blackout" Property="Opacity" Value="0.2"/>

 

                            </Trigger>

                            <Trigger Property="IsFocused" Value="True">

                                <Setter TargetName="DayButtonFocusVisual" Property="Visibility" Value="Visible"/>

                            </Trigger>

                            <Trigger Property="IsFocused" Value="False">

                                <Setter TargetName="DayButtonFocusVisual" Property="Visibility" Value="Collapsed"/>

                            </Trigger>

                            <Trigger Property="IsInactive" Value="True">

                                <Setter TargetName="NormalText" Property="TextElement.Foreground" Value="#FF777777"/>

                            </Trigger>

                        </ControlTemplate.Triggers>

                    </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style>

    </Window.Resources>

    <Grid>

 

        <syncfusion:DateTimeEdit x:Name="dateTimeEdit" Height="25" Width="200" Pattern="ShortDate" />

 

    </Grid>

 

 

 

Background customization of the Calendar used in the DateTimeEdit

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied