WPF button takes two clicks to fire Click event

后端 未结 2 813
南笙
南笙 2021-02-20 15:51

I have a TabItem which contains a calendar control and a button. The issue is that when the calendar\'s selected date is the same as the previously selected date, the button tak

2条回答
  •  北海茫月
    2021-02-20 16:40

    This was the best answer I found on the web. It's still not perfect because it doesn't help with buttons that are marked as IsDefault or IsCancel

    protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
    {
      base.OnPreviewMouseUp(e);
      if (Mouse.Captured is Calendar || Mouse.Captured is System.Windows.Controls.Primitives.CalendarItem)
      {
        Mouse.Capture(null);
      }
    }
    

提交回复
热议问题