WPF button takes two clicks to fire Click event

后端 未结 2 851
南笙
南笙 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:26

    You could simply write:

    Mouse.Capture(null);
    

    This will solve the issue of mouse holding focus

    0 讨论(0)
  • 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);
      }
    }
    
    0 讨论(0)
提交回复
热议问题