This is a migrated thread and some comments may be shown as answers.

Trigger for "Today" button inside RadDatePicker

1 Answer 161 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Parul
Top achievements
Rank 1
Parul asked on 09 Jul 2011, 01:19 PM
Hi All,
I am working on the Wpf 4.0 and using MVVM and Prism in my application.
I have added the Today button inside the control template for the RadTimePicker which is defined inside a resource dictionary.
Following is the code snippets for it (Bold and Italics part I have added to the control template of the RadDateTimePickerControlTemplate ):

 

 

 

 

<telerik:RadDropDownButton x:Name="PART_DropDownButton" CloseOnEnter="True" Grid.Column="1" DropDownIndicatorVisibility="Collapsed" Focusable="False" telerik:DateTimePickerExtensions.FocusContentOnOpen="True" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="-1,0,0,0" Padding="0" PopupPlacementTarget="{Binding ElementName=PART_DateTimeInput}" TabIndex="1" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"><telerik:RadDropDownButton.DropDownContent>

 

 

 

<Grid>

 

 

 

 

<Grid.ColumnDefinitions>

 

 

 

 

<ColumnDefinition Width="*"/>

 

 

 

 

<ColumnDefinition Width="*"/>

 

 

 

 

</Grid.ColumnDefinitions>

 

 

 

 

<Grid.RowDefinitions>

 

 

 

 

<RowDefinition/>

 

 

 

 

<RowDefinition/>

 

 

 

 

<RowDefinition Height="33"/>

 

 

 

 

</Grid.RowDefinitions>

 

 

 

 

<telerik:RadCalendar x:Name="PART_Calendar"

 

 

 

Culture="{TemplateBinding Culture}"

 

 

 

Grid.Column="0"

 

 

 

DisplayDateEnd="{Binding DisplayDateEnd, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" DateSelectionMode="{TemplateBinding DateSelectionMode}"

 

 

 

DisplayDateStart="{Binding DisplayDateStart, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" DisplayDate="{Binding DisplayDate, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"

 

 

 

IsReadOnly="{TemplateBinding IsReadOnly}"

 

 

 

Grid.Row="0"

 

 

 

Style="{TemplateBinding CalendarStyle}"

 

 

 

SelectableDateEnd="{Binding SelectableDateEnd, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"

 

 

 

SelectionMode="Single"

 

 

 

SelectedDate="{Binding SelectedDate, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"

 

 

 

SelectableDateStart="{Binding SelectableDateStart, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">

 

 

 

 

</telerik:RadCalendar>

 

 

 

 

<telerik:DateTimePickerClock x:Name="PART_Clock" Culture="{TemplateBinding Culture}" Grid.Column="1" EndTime="{TemplateBinding EndTime}" Header="Clock" IsReadOnly="{TemplateBinding IsReadOnly}" Grid.Row="0" Style="{TemplateBinding ClockStyle}" SelectedTime="{Binding SelectedTime, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" StartTime="{TemplateBinding StartTime}" TimeInterval="{Binding TimeInterval, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">

 

 

 

 

</telerik:DateTimePickerClock>

 

 

 

 

<StackPanel Grid.Row="2" Background="#ABACA7" >

 

 

 

 

<Border BorderThickness="1" Grid.Row="2" VerticalAlignment="Top" BorderBrush="whitesmoke" Margin="1" >

 

 

 

 

<Button Style="{StaticResource DatePickerButton}" Content="Today" />

 

 

 

 

</Border>

 

 

 

 

</StackPanel>

 

 

 

 

<!--Date Picker Button Style -->

 

 

 

 

 

 

 

 

<Style x:Key="DatePickerButton" TargetType="Button">

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

<Setter Property="BorderBrush" Value="#91918F"/>

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

<Setter Property="BorderThickness" Value="1"/>

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

<Setter Property="Height" Value="24"/>

 

 

 

 

 

 

 

 

<Setter Property="Width" Value="50"/>

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

<Setter Property="FontWeight" Value="ExtraBold"/>

 

 

 

 

 

 

 

 

<Setter Property= "Margin" Value="2"/>

 

 

 

 

 

 

 

 

<Setter Property= "Cursor" Value="Hand"/>

 

 

 

 

 

 

 

 

<Setter Property="Template">

 

 

 

 

 

 

 

 

<Setter.Value>

 

 

 

 

 

 

 

 

<ControlTemplate TargetType="Button">

 

 

 

 

 

 

 

 

<Border BorderThickness="{TemplateBinding BorderThickness}"

 

 

 

 

 

 

 

BorderBrush="{TemplateBinding BorderBrush}"

 

 

 

 

 

 

 

Background="{TemplateBinding Background}"

 

 

 

 

 

 

 

Padding="{TemplateBinding Padding}"

 

 

 

CornerRadius="2.8"

 

 

 

>

 

 

 

 

 

 

 

 

<ContentControl Content="{TemplateBinding Content}"

 

 

 

HorizontalAlignment="Center"

 

 

 

VerticalAlignment="Center"/>

 

 

 

 

 

 

 

 

</Border>

 

 

 

 

 

 

 

 

</ControlTemplate>

 

 

 

 

 

 

 

 

</Setter.Value>

 

 

 

 

 

 

 

 

</Setter>

 

 

 

 

 

 

 

 

<Style.Triggers>

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

<Setter Property="BorderBrush" Value="Gold"/>

 

 

 

 

 

 

 

 

</Trigger>

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

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

 

 

 

 

 

 

 

 

<Setter Property="BorderBrush" Value="Orange"/>

 

 

 

 

 

 

 

 

</Trigger>

 

 

 

 

 

 

 

 

</Style.Triggers>

 

 

 

 

 

 

 

 

</Style>

 

 

 

 


Now in our application we have created a custom control for RadTimePicker , and I need to apply a trigger on today button that on clickof this "Today" button i should get today's date selected in the calendar.

So can I write any trigger in my style to do so ???? or how can we do this in present scenerio ???

Thanks in advance !!!!

1 Answer, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 13 Jul 2011, 08:31 AM
Hi Parul,

Create a routed command. Assign it on the button. Add handler for it in your custom control that would select the today date.

It can not get easier than that although the routed commands usually introduce some confusion in developers they are well supported in WPF.

Greetings,
Pana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
DatePicker
Asked by
Parul
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or