Datetime control context menu

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

  • Posted 5 August 2020, 3:26 am EST

    Dear team,

    I have date time control and I am displaying custom context menu.
    When I disable the grid in which date time controls are present, context menu should not be displayed.
    But it is getting displayed even though control is disabled..
    For displaying the context menu I got following reply from forum only.

    private void datePicker_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
    {
    datePicker.ContextMenu.IsOpen = true;
    datePicker.ContextMenu.PlacementTarget = datePicker;
    }
  • Replied 5 August 2020, 6:23 pm EST

    Hi Mayur,

    This seems like a bug in our control and we have escalated it to the devs (TFS ID: 456468).

    However, as a workaround, you can override the default ContextMenu of the templated C1MaskedTextBox inside DatePicker using Loaded event as follows:

    private void datePicker_Loaded(object sender, RoutedEventArgs e)
    {
    var maskedTextBox = datePicker.Template.FindName("TextBox", datePicker) as C1MaskedTextBox;
    maskedTextBox.ContextMenu = datePicker.ContextMenu;
    }

    Also, when using this you don't have to use PreviewMouseRightButtonUp event to show context menu.

    Regards,
    Basant
  • Replied 5 August 2020, 8:58 pm EST

    OK

    I will try that solution.
    From forum only I got the solution for another thread and used PreviewMouseRightButtonUp event.
  • Marked as Answer

    Replied 6 August 2020, 8:02 pm EST

    Hi Mayur,

    As per the devs it is not a bug in our control. It is standard behavior of MS Textbox. You can also verify it with the standard Textbox.

    Regards,
    Basant
  • Replied 10 August 2020, 10:33 pm EST

    Dear Team,

    I did the above setting for my timepicker control.
    following are the settings.

    When I do the control+ A and select Cut context menu, Cut operation is working successfully.
    When I select the complete text of time picker control using Mouse drag and select Cut context menu, Cut operation is working successfully but width of TimerPicker is shrink.

    PFA for the same.

  • Replied 10 August 2020, 10:34 pm EST

  • Replied 11 August 2020, 10:49 pm EST

    Hi Mayur,

    I could reproduce the behavior only when both TimeEditor and its container is of Auto width. Also, I have observed the same behavior with standard Textbox.

    So, the issue doesn't seem related to the TimeEditor. However, You may explicitly set the Width property for TimeEditor to avoid this behavior.

    In case there is something that I might have missed, please let me know.

    Regards,
    Basant
  • Replied 12 August 2020, 1:54 am EST

    Yes I set the width as Auto because on some PC time gets cut and on some PC (Japanese OS) it is correct. I kept the width as 70.

    Could you please let me know how much width I can kept so that string is fit in it.
  • Replied 12 August 2020, 5:55 pm EST

    Can you try setting an optimal width such that clipping doesn't happen? For example, you can set a larger (> 70) width of TimeEditor which will prevent the time from cutting.

    ~ Basant
  • Replied 13 August 2020, 6:40 pm EST

    Yes On Japanese OS , it shows correct.
    But in this case unnecessary space is added when it is displayed on English OS system.
  • Replied 13 August 2020, 11:46 pm EST

    Hi Mayur,

    You can set the TimeEditor's Width based on the current culture with the help of a converter. Please refer to attached sample for the same.

    Also, can you please verify from the attached sample that second TimeEditor is cutting the time and share the outcomes? I couldn't observe any difference in behaviors on English and Japanese machines.

    ~ Basant

    TimeEditorWidth.zip
  • Replied 6 September 2020, 9:08 pm EST

    Dear Team,

    As I was facing a problem with Auto width for time control and Cut context menu option (Please go through the above thread) I tried the below approach.

    I have kept the width as Auto so that it will be auto fit and Min width as 72 so that after cut option, it will not get shrink.

    I have two timer control, for one it is working correctly but for the other one, it is not working properly even though all properties of both the controls are the same.

    Could you please check my sample solution and let me know the problem as this is a very weird behavior. I have also attached the image and highlighted the problem part.

    WidthIssue.zip
  • Replied 8 September 2020, 12:50 am EST

    Hi Mayur,

    The issue is because you are setting the MinWidth of first TimeEditor's MaskedTextBox inside TimeEditor's Loaded event handler as follows:

    private void startTime_Loaded(object sender, RoutedEventArgs e)
    {
    var MaskedTextBox = startTime.Template.FindName("TextBox", startTime) as C1MaskedTextBox;
    // Setting min width here
    MaskedTextBox.MinWidth = startTime.MinWidth;
    MaskedTextBox.ContextMenu = startTime.ContextMenu;
    }


    Removing this setting would resolve the issue.

    Regards,
    Basant
Need extra support?

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

Learn More

Forum Channels