Have to click away twice from Calendar in WPF

后端 未结 7 1829
南旧
南旧 2021-02-01 19:17

Edit 2: Thank you all for your feedback. I solved the problem by adding this to my SelectedDatesChanged event:

Mouse.Capture(null);

When I select a

7条回答
  •  旧巷少年郎
    2021-02-01 19:51

    If you select the same date then SelectedDatesChanged won't be raised and you will see the same issue where you need to click twice.

    Ideally you should hook to GotMouseCapture event and release the mouse capture from original sender to avoid any mouse captures by calendar control.

    private void calendar_GotMouseCapture(object sender, MouseEventArgs e)
    {
        UIElement originalElement = e.OriginalSource as UIElement;
        if (originalElement != null)
        {
            originalElement.ReleaseMouseCapture();
        }
    }
    

    Note - You can extract out this in behavior as well by using attached property like mentioned in another answer.

提交回复
热议问题