Date Control issue of copy paste

Posted by: mayur.purandare on 5 August 2020, 3:26 am EST

    • Post Options:
    • Link

    Posted 5 August 2020, 3:26 am EST

    Dear Team,

    I am able to copy timepicker control data in DatePicker control.

    It should not allow/accept as it is Date picker control.

    PFA.WpfApplication2.zip

  • Posted 5 August 2020, 7:00 pm EST

    Hi Mayur,

    Thanks for the sample application. This seems to be a bug and has been escalated to the devs (TFS ID: 456473).

    However, as a workaround, you can get the the C1MaskedTextBox from DatePicker’s Template and handle its TextChanged event to explicitly validate the same as follows:

    private void startDate_Loaded(object sender, RoutedEventArgs e)
    
          var maskedTextBox = startDate.Template.FindName("TextBox", startDate) as C1MaskedTextBox;
          maskedTextBox.TextChanged += MaskedTextBox_TextChanged;
    }
    
    private void MaskedTextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
          var maskedTxt = sender as C1MaskedTextBox;
    
          string[] timeFormats = new string[] { "hh\\:mm\\:ss", "h\\:m\\:s", "hh\\:mm\\:ss tt" };
    
          if (TimeSpan.TryParseExact(maskedTxt.Text, timeFormats, CultureInfo.CurrentCulture, TimeSpanStyles.None , out TimeSpan t))
          {
              maskedTxt.Text = startDate.SelectedDate.Value.Date.ToString(startDate.CustomFormat);
          }
    }
    

    Regards,

    Basant

  • Posted 10 August 2020, 9:48 pm EST

    Hi Mayur,

    As per the devs, it is not a bug because a time string (e.g. “00:00:00”) can be parsed into a valid DateTime object with date being today’s date.

    You can verify with the below code:

    var test = DateTime.Parse("12:00:00 AM", CultureInfo.CurrentCulture);
    Console.WriteLine(test);
    
    

    So, when we provide time in C1DatePicker it gets parsed into a valid DateTime object by the .NetFramework and hence the parsed time string is accepted by C1DatePicker. Also, the same behavior is with the MS DatePicker.

    However, displaying time string of the parsed input in a DatePicker control after validation is incorrect and is accepted as a bug. And the fix is expected to be released in 2020v3.

    Regards,

    Basant

  • Posted 25 August 2020, 5:25 pm EST

    Hi Mayur,

    This is to inform you that C1DatePicker now (in 2020v2 HotFix 1) displays the parsed Date instead of time when time string is input. Please find the latest builds from the following link:

    http://prerelease.componentone.com/hotfixes/wpf/C1WPFBasicLibrary.4.5.2_4.5.20202.719.zip

    Regards,

    Basant

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels