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

Click events are not rising when clicking on RadDetaTimePicker date region

2 Answers 90 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
v00d00
Top achievements
Rank 1
v00d00 asked on 20 Feb 2012, 05:18 PM
Hi, we have a control which is using RadDateTimePicker in it.

XAML:

<UserControl x:Class="EmpresaHr.Controls.SlashedDateTimePicker"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             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

2 Answers, 1 is accepted

Sort by
0
Grégory
Top achievements
Rank 1
answered on 03 May 2012, 09:51 AM
I need this too.

 <telerik:RadDateTimePicker x:Name="dtpDateTime" Width="200" HorizontalAlignment="Center" VerticalAlignment="Center"
                                   MouseLeftButtonUp="dtpDateTime_MouseLeftButtonUp" 
                                   MouseLeftButtonDown="dtpDateTime_MouseLeftButtonDown">            
 </telerik:RadDateTimePicker>


Events aren't raised!





private void dtpDateTime_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (e.ClickCount >= 2)
			{
				if (dtpDateTime.IsDropDownOpen)
				{					
					dtpDateTime.IsDropDownOpen = false;
				}
			}
		}
 
private void dtpDateTime_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			if (e.ClickCount >= 2)
			{
				if (dtpDateTime.IsDropDownOpen)
				{					
					dtpDateTime.IsDropDownOpen = false;
				}
			}
		}


0
Ivo
Telerik team
answered on 08 May 2012, 10:51 AM
Hi,

I fear that this cannot be achieved with the current version of RadCalendar control. I would suggest you to use the RadCalendar's SelectionChanged event in order to close the opened popup.

Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DateTimePicker
Asked by
v00d00
Top achievements
Rank 1
Answers by
Grégory
Top achievements
Rank 1
Ivo
Telerik team
Share this question
or