This question is locked. New answers and comments are not allowed.
Hi, we have a control which is using RadDateTimePicker in it.
XAML:
.cs
So what is this stuff does is it mimic default calendar control behaviour but using masked textbox for date input.
Now we want to hide the popubButton content when user doubleclicks the date on calendar. But events are only rised if I click enywhere on calendar control except the region with dates.
Telerik : 2012.1.215.1050
Silverlight: 5
XAML:
<UserControl x:Class="EmpresaHr.Controls.SlashedDateTimePicker" xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" d:DesignHeight="21" d:DesignWidth="200" mc:Ignorable="d"> <Grid x:Name="LayoutRoot"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="ValidationStates"> <VisualState x:Name="Valid" /> <VisualState x:Name="InvalidUnfocused"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="InvalidFocused"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <Visibility>Visible</Visibility> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsOpen"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <System:Boolean>True</System:Boolean> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="xform" Storyboard.TargetProperty="X" To="0"> <DoubleAnimation.EasingFunction> <BackEase Amplitude=".3" EasingMode="EaseOut" /> </DoubleAnimation.EasingFunction> </DoubleAnimation> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Controls:RadMaskedDateTimeInput x:Name="maskedTextBox" Grid.Column="0" Culture="en-GB" UpdateValueEvent="PropertyChanged" HorizontalAlignment="Stretch" /> <telerik:RadDropDownButton x:Name="dropDownButton" Grid.Column="1" DropDownIndicatorVisibility="Collapsed"> <Image Style="{StaticResource GridImageStyle}"/> <telerik:RadDropDownButton.DropDownContent> <Grid x:Name="calendarView" Height="165" MouseLeftButtonDown="CalendarClick"> <Controls:RadCalendar x:Name="radCalendar" MouseLeftButtonDown="CalendarClick" DateSelectionMode="Day" DisplayMode="MonthView" /> </Grid> </telerik:RadDropDownButton.DropDownContent> </telerik:RadDropDownButton> <Border x:Name="ValidationErrorElement" Grid.ColumnSpan="2" BorderBrush="#FFDB000C" BorderThickness="1" CornerRadius="1" Visibility="Collapsed" Margin="1"> <ToolTipService.ToolTip> <ToolTip x:Name="validationTooltip" Placement="Right" Opacity="1"> <ToolTip.Triggers> <EventTrigger RoutedEvent="Canvas.Loaded"> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip" Storyboard.TargetProperty="IsHitTestVisible"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <System:Boolean>true</System:Boolean> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> </ToolTip.Triggers> <ToolTip.Template> <ControlTemplate TargetType="ToolTip"> <Border x:Name="Root" CornerRadius="2" BorderThickness="0" Background="Transparent" BorderBrush="Transparent"> <Border BorderBrush="Transparent" BorderThickness="0" CornerRadius="1" Background="Transparent" Padding="0"> <Border.Resources> <Storyboard x:Key="Visible State"/> <Storyboard x:Key="Normal State"/> </Border.Resources> <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Cursor="{TemplateBinding Cursor}" Margin="{TemplateBinding Padding}"/> </Border> </Border> </ControlTemplate> </ToolTip.Template> <ToolTip.Content> <Grid x:Name="Root" Opacity="1"> <Grid.RenderTransform> <TranslateTransform x:Name="xform" X="-10" /> </Grid.RenderTransform> <Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5" /> <Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4" /> <Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3" /> <Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2" /> <Border Background="#FFDC000C" CornerRadius="2" /> <Border CornerRadius="2" Opacity="1"> <TextBlock x:Name="tbError" MaxWidth="250" Margin="4" Foreground="White" TextWrapping="Wrap" UseLayoutRounding="false" /> </Border> </Grid> </ToolTip.Content> </ToolTip> </ToolTipService.ToolTip> <Grid Width="12" Height="12" Margin="1,-4,-4,0" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Transparent"> <Path Margin="1,3,0,0" Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="#FFDC000C" /> <Path Margin="1,3,0,0" Data="M 0,0 L2,0 L 8,6 L8,8" Fill="#ffffff" /> </Grid> </Border> </Grid></UserControl>.cs
namespace EmpresaHr.Controls{ using System; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using Telerik.Windows.Controls; using Telerik.Windows; using PropertyMetadata = System.Windows.PropertyMetadata; [TemplateVisualState(Name = StateValid, GroupName = GroupValidation)] [TemplateVisualState(Name = StateInvalidFocused, GroupName = GroupValidation)] [TemplateVisualState(Name = StateInvalidUnFocused, GroupName = GroupValidation)] public partial class SlashedDateTimePicker { public static DependencyProperty CultureProperty = DependencyProperty.Register( "Culture", typeof(CultureInfo), typeof(SlashedDateTimePicker), new FrameworkPropertyMetadata()); public CultureInfo Culture { get { return (CultureInfo)this.GetValue(CultureProperty); } set { SetValue(CultureProperty, value); } } public const string GroupValidation = "ValidationStates"; public const string StateValid = "Valid"; public const string StateInvalidFocused = "InvalidFocused"; public const string StateInvalidUnFocused = "InvalidUnfocused"; public const string StatePopupOpen = "Open"; public const string StatePopupClosed = "Closed"; public SlashedDateTimePicker() { InitializeComponent(); // for task Feature #8129 Datepicker behavour maskedTextBox.ClearCommand = new DelegateCommand((arg) => { maskedTextBox.Value = null; maskedTextBox.Focus(); }); this.BindingValidationError += (s, e) => UpdateValidationState(); var slectedDateBinding = new Binding() { Source = this, Path = new PropertyPath("SelectedDate"), Mode = BindingMode.TwoWay }; var slectedDateBindingForCalendar = new Binding() { Source = this, Path = new PropertyPath("SelectedDate"), Mode = BindingMode.TwoWay }; var emptyContentBinding = new Binding { Source = this, Path = new PropertyPath("EmptyContent"), Mode = BindingMode.TwoWay }; maskedTextBox.SetBinding(RadMaskedDateTimeInput.ValueProperty, slectedDateBinding); maskedTextBox.SetBinding(RadMaskedInputBase.EmptyContentProperty, emptyContentBinding); radCalendar.SetBinding(RadCalendar.SelectedDateProperty, slectedDateBindingForCalendar); radCalendar.SetBinding(RadCalendar.DisplayDateProperty, slectedDateBindingForCalendar); validationTooltip.PlacementTarget = this; } private void UpdateValidationState() { if (Validation.GetErrors(this).Any()) { if (this.maskedTextBox.IsFocused) { VisualStateManager.GoToState(this, StateInvalidFocused, true); Root.Opacity = 1; } else { VisualStateManager.GoToState(this, StateInvalidUnFocused, true); } tbError.Text = (string)Validation.GetErrors(this).First().ErrorContent; } else { tbError.Text = null; VisualStateManager.GoToState(this, StateValid, true); } } #region SelectedDate (DependencyProperty) /// <summary> /// A description of the property. /// </summary> public DateTime? SelectedDate { get { return (DateTime?)GetValue(SelectedDateProperty); } set { SetValue(SelectedDateProperty, value); } } public static readonly DependencyProperty SelectedDateProperty = DependencyProperty.Register("SelectedDate", typeof(DateTime?), typeof(SlashedDateTimePicker), new PropertyMetadata(null)); #endregion #region EmtpyContent (DependencyProperty) /// <summary> /// Provides access to the empty content property on the control /// </summary> public string EmtpyContent { get { return (string)GetValue(EmtpyContentProperty); } set { SetValue(EmtpyContentProperty, value); } } public static readonly DependencyProperty EmtpyContentProperty = DependencyProperty.Register("EmtpyContent", typeof(string), typeof(SlashedDateTimePicker), new PropertyMetadata("Empty")); #endregion private void CalendarClick(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 2 ||true) { this.dropDownButton.IsOpen = false; }
} }}So what is this stuff does is it mimic default calendar control behaviour but using masked textbox for date input.
Now we want to hide the popubButton content when user doubleclicks the date on calendar. But events are only rised if I click enywhere on calendar control except the region with dates.
Telerik : 2012.1.215.1050
Silverlight: 5