Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
920
Regarding DatePicker
posted

Hi,

i have created a custom style for the datepicker and for its calendar i also customized the calendarbuttonstyle. in the calendar button i added a mousedown event to capture when the user has clicked on a certain month. I have two datepickers with the same style. However, when in the mousedown event i am not being able to know which datepicker was clicked. Can you help? below is the style for the datepickers. "MonthClick" is the function that captures the mousedown event. I want to be able to know which datepicker was clicked. Thanks.

<Style x:Key="CustomDatePicker" TargetType="sdk:DatePicker">

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="sdk:DatePicker">

                        <Grid>

                            <Grid.Resources>

                                <SolidColorBrush x:Key="DisabledBrush" Color="#8CFFFFFF"/>

                                <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="Button">

                                    <Grid FlowDirection="LeftToRight">

                                        <VisualStateManager.VisualStateGroups>

                                            <VisualStateGroup x:Name="CommonStates">

                                                <VisualStateGroup.Transitions>

                                                    <VisualTransition GeneratedDuration="0"/>

                                                    <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>

                                                    <VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/>

                                                </VisualStateGroup.Transitions>

                                                <VisualState x:Name="Normal"/>

                                                <VisualState x:Name="MouseOver">

                                                    <Storyboard>

                                                        <ColorAnimation Duration="0" To="#FF448DCA" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"/>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                    </Storyboard>

                                                </VisualState>

                                                <VisualState x:Name="Pressed">

                                                    <Storyboard>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#FF448DCA"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                        <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight">

                                                            <SplineDoubleKeyFrame KeyTime="0" Value="1"/>

                                                        </DoubleAnimationUsingKeyFrames>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#EAFFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#6BFFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                        <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">

                                                            <SplineColorKeyFrame KeyTime="0" Value="#F4FFFFFF"/>

                                                        </ColorAnimationUsingKeyFrames>

                                                    </Storyboard>

                                                </VisualState>

                                                <VisualState x:Name="Disabled">

                                                    <Storyboard>

                                                        <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="DisabledVisual">

                                                            <SplineDoubleKeyFrame KeyTime="0" Value="1"/>

                                                        </DoubleAnimationUsingKeyFrames>

                                                    </Storyboard>

                                                </VisualState>

                                            </VisualStateGroup>

                                        </VisualStateManager.VisualStateGroups>

                                        <Grid Background="#11FFFFFF" HorizontalAlignment="Center" Height="20" Margin="0" VerticalAlignment="Center" Width="21">

                                            <Grid.ColumnDefinitions>

                                                <ColumnDefinition Width="20*"/>

                                                <ColumnDefinition Width="20*"/>

                                                <ColumnDefinition Width="20*"/>

                                                <ColumnDefinition Width="20*"/>

                                            </Grid.ColumnDefinitions>

                                            <Grid.RowDefinitions>

                                                <RowDefinition Height="23*"/>

                                                <RowDefinition Height="19*"/>

                                                <RowDefinition Height="19*"/>

                                                <RowDefinition Height="19*"/>

                                            </Grid.RowDefinitions>

                                            <Border x:Name="Highlight" BorderBrush="#FF6DBDD1" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius="0,0,1,1" Margin="-1" Opacity="0" Grid.Row="0" Grid.RowSpan="4"/>

                                            <Border x:Name="Background" BorderBrush="#FFFFFFFF" BorderThickness="1" Background="#FF1F3B53" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3"/>

                                            <Border x:Name="BackgroundGradient" BorderBrush="#BF000000" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3">

                                                <Border.Background>

                                                    <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">

                                                        <GradientStop Color="#FFFFFFFF" Offset="0"/>

                                                        <GradientStop Color="#F9FFFFFF" Offset="0.375"/>

                                                        <GradientStop Color="#E5FFFFFF" Offset="0.625"/>

                                                        <GradientStop Color="#C6FFFFFF" Offset="1"/>

                                                    </LinearGradientBrush>

                                                </Border.Background>

                                            </Border>

                                            <Rectangle Grid.ColumnSpan="4" Grid.RowSpan="1" StrokeThickness="1">

                                                <Rectangle.Fill>

                                                    <LinearGradientBrush EndPoint="0.3,-1.1" StartPoint="0.46,1.6">

                                                        <GradientStop Color="#FF4084BD"/>

                                                        <GradientStop Color="#FFAFCFEA" Offset="1"/>

                                                    </LinearGradientBrush>

                                                </Rectangle.Fill>

                                                <Rectangle.Stroke>

                                                    <LinearGradientBrush EndPoint="0.48,-1" StartPoint="0.48,1.25">

                                                        <GradientStop Color="#FF494949"/>

                                                        <GradientStop Color="#FF9F9F9F" Offset="1"/>

                                                    </LinearGradientBrush>

                                                </Rectangle.Stroke>

                                            </Rectangle>

                                            <Path Grid.ColumnSpan="4" Grid.Column="0" Data="M11.426758,8.4305077 L11.749023,8.4305077 L11.749023,16.331387 L10.674805,16.331387 L10.674805,10.299648 L9.0742188,11.298672 L9.0742188,10.294277 C9.4788408,10.090176 9.9094238,9.8090878 10.365967,9.4510155 C10.82251,9.0929432 11.176106,8.7527733 11.426758,8.4305077 z M14.65086,8.4305077 L18.566387,8.4305077 L18.566387,9.3435936 L15.671368,9.3435936 L15.671368,11.255703 C15.936341,11.058764 16.27293,10.960293 16.681133,10.960293 C17.411602,10.960293 17.969301,11.178717 18.354229,11.615566 C18.739157,12.052416 18.931622,12.673672 18.931622,13.479336 C18.931622,15.452317 18.052553,16.438808 16.294415,16.438808 C15.560365,16.438808 14.951641,16.234707 14.468243,15.826504 L14.881817,14.929531 C15.368796,15.326992 15.837872,15.525723 16.289043,15.525723 C17.298809,15.525723 17.803692,14.895514 17.803692,13.635098 C17.803692,12.460618 17.305971,11.873379 16.310528,11.873379 C15.83071,11.873379 15.399232,12.079271 15.016094,12.491055 L14.65086,12.238613 z" Fill="#FF2F2F2F" HorizontalAlignment="Center" Margin="4,3,4,3" Grid.Row="1" Grid.RowSpan="3" RenderTransformOrigin="0.5,0.5" Stretch="Fill" VerticalAlignment="Center"/>

                                            <Ellipse Grid.ColumnSpan="4" Fill="#FFFFFFFF" HorizontalAlignment="Center" Height="3" StrokeThickness="0" VerticalAlignment="Center" Width="3"/>

                                            <Border x:Name="DisabledVisual" BorderBrush="#B2FFFFFF" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius="0,0,.5,.5" Opacity="0" Grid.Row="0" Grid.RowSpan="4"/>

                                        </Grid>

                                    </Grid>

                                </ControlTemplate>

                            </Grid.Resources>

                             <Grid.RowDefinitions>

                                <RowDefinition Height="Auto"/>

                                  <RowDefinition Height="Auto"/>

                            </Grid.RowDefinitions>

                            <TextBox x:Name="CalTextBox" HorizontalAlignment="Left" Grid.Column="0" Height="24" Width="79" Background="{x:Null}"/>

                            <Button x:Name="Button" Click="ShowCalendar" Grid.Column="1" Margin="0,0,-4,0" Template="{StaticResource DropDownButtonTemplate}" />

                            <sdk:Calendar x:Name="Calendar" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="0" DisplayModeChanged="Calendar_DisplayModeChanged" DisplayMode="Year" Visibility="Collapsed" Tag="">

                                <sdk:Calendar.CalendarButtonStyle>

                                    <Style TargetType="System_Windows_Controls_Primitives:CalendarButton">

                                        <Setter Property="Background" Value="#FFBADDE9"/>

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

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

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

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

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

                                        <Setter Property="Template">

                                            <Setter.Value>

                                                <ControlTemplate TargetType="System_Windows_Controls_Primitives:CalendarButton">

                                                    <Grid Tag="{TemplateBinding Property=Name}" MouseLeftButtonDown="MonthClick">

                                                        <VisualStateManager.VisualStateGroups>

                                                            <VisualStateGroup x:Name="CommonStates">

                                                                <VisualStateGroup.Transitions>

                                                                    <VisualTransition GeneratedDuration="0:0:0.1"/>

                                                                </VisualStateGroup.Transitions>

                                                                <VisualState x:Name="Normal"/>

                                                                <VisualState x:Name="MouseOver">

                                                                    <Storyboard>

                                                                        <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Background"/>

                                                                    </Storyboard>

                                                                </VisualState>

                                                                <VisualState x:Name="Pressed">

                                                                    <Storyboard>

                                                                        <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Background"/>

                                                                    </Storyboard>

                                                                </VisualState>

                                                            </VisualStateGroup>

                                                            <VisualStateGroup x:Name="SelectionStates">

                                                                <VisualStateGroup.Transitions>

                                                                    <VisualTransition GeneratedDuration="0"/>

                                                                </VisualStateGroup.Transitions>

                                                                <VisualState x:Name="Unselected"/>

                                                                <VisualState x:Name="Selected">

                                                                    <Storyboard>

                                                                        <DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBackground"/>

                                                                    </Storyboard>

                                                                </VisualState>

                                                            </VisualStateGroup>

                                                            <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="(ContentControl.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Content"/>

                                                                    </Storyboard>

                                                                </VisualState>

                                                            </VisualStateGroup>

                                                            <VisualStateGroup x:Name="CalendarButtonFocusStates">

                                                                <VisualStateGroup.Transitions>

                                                                    <VisualTransition GeneratedDuration="0"/>

                                                                </VisualStateGroup.Transitions>

                                                                <VisualState x:Name="CalendarButtonFocused">

                                                                    <Storyboard>

                                                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisual">

                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>

                                                                        </ObjectAnimationUsingKeyFrames>

                                                                    </Storyboard>

                                                                </VisualState>

                                                                <VisualState x:Name="CalendarButtonUnfocused">

                                                                    <Storyboard>

                                                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisual">

                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>

                                                                        </ObjectAnimationUsingKeyFrames>

                                                                    </Storyboard>

                                                                </VisualState>

                                                            </VisualStateGroup>

                                                        </VisualStateManager.VisualStateGroups>

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

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

                                                        <ContentControl x:Name="Content" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="#FF333333" FontSize="{TemplateBinding FontSize}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsTabStop="False" Margin="1,0,1,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

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

                                                    </Grid>

                                                </ControlTemplate>

                                            </Setter.Value>

                                        </Setter>

                                    </Style>

                                </sdk:Calendar.CalendarButtonStyle>

                            </sdk:Calendar>

                        </Grid>

                   </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style>

 

Parents
No Data
Reply
  • 138253
    Offline posted

    Hello Nazha,

     

    It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking into your requirement and the Style you have provided, but since I believe you have code in the handlers of two Buttons and a Grid I cannot be completely sure what cause your issue. Although I can suggest you use the EventArgs’ OriginalSource Property to get the DataPicker’s Name or cast the sender to DatePicker if it is so. If this doesn’t help you, could you please send me an isolated sample project, where this is reproduced, so I can investigate it further for you.

     

    Feel free to write me if you have further questions.

Children
No Data