WPF 按钮需要单击两次才能触发 Click 事件
我有一个 TabItem,其中包含一个日历控件和一个按钮。问题是,当日历的选择日期与先前选择的日期相同时,该按钮需要单击两次才能触发其 Click 事件。
我实现了日历的 selectedDatesChanged 事件来解决当当前选择的日期与之前选择的日期不同时的这个问题。代码如下:
selectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
this.CaptureMouse();
this.ReleaseMouseCapture();
}
我正在寻找的是一种当日历的 selectedDate 与先前选择的日期没有不同时具有与上述函数所示相同效果的方法。 我尝试处理 GotFocus 和 MouseUp 事件,但并不能解决问题。
有人对我如何解决这个问题有任何想法吗?
谢谢, 纳文
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 takes two clicks to fire its Click event.
I have implemented the selectedDatesChanged event of the calendar to solve this problem when the current selected date is different from the previous selection. The code is as below:
selectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
this.CaptureMouse();
this.ReleaseMouseCapture();
}
What I'm looking for is a way to have the same effect shown in the above function when the selectedDate of the calendar does not differ from the previously selected date.
I tried handling the GotFocus and MouseUp events, but it doesn't solve the problem.
Does anyone have any ideas on how I could solve this issue?
Thanks,
Naveen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我在网上找到的最好答案。它仍然不完美,因为它对标记为 IsDefault 或 IsCancel 的按钮没有帮助
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
你可以简单地写:
这将解决鼠标保持焦点的问题
You could simply write:
This will solve the issue of mouse holding focus