弹出消息框以确认日期选择器问题
我在 Silverlight 2 中使用普通日期选择器。我将所选日期绑定到一个值,当该值更改时,我会弹出一个消息框以确认他们想要更改该值。
然而,当我在日期选择器的值更改后立即使用消息框时,会发生奇怪的行为。日期选择器的弹出窗口不会关闭,如果您将鼠标悬停在日历上,它将选择一个日期,而无需单击鼠标。
此外,发生这种情况后,它似乎会影响绑定,并且在重新加载页面之前无法再次设置视图模型的属性。
这个问题相当具体,所以我附上了一个精简的示例。选择一个日期并按“确定”,然后将鼠标移到日历上以重现该日期。
我的 XAML -
<Grid x:Name="LayoutRoot">
<controls:DatePicker x:Name="dpTest"
Height="25"
Width="75"
SelectedDateChanged="DatePicker_SelectedDateChanged" />
</Grid>
我的代码背后 -
Private Sub DatePicker_SelectedDateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
MessageBox.Show("Test Popup")
End Sub
有什么想法或解决方法吗?
I am using the vanilla datepicker in Silverlight 2. I bind the selected date to a value, and when that value changes I pop a messagebox to confirm that they would like to change the value.
However strange behaviour ensues when I use a messagebox straight after the datepicker's value is changed. The datepicker's popup will not close, and if you mouse over the calendar it will choose a date without having to click the mouse.
Also, after this occurs it seems to affect bindings and it cannot set the view model's property again until the page is reloaded.
This problem is rather specific so I have attached a stripped down example. Choose a date and press OK then move your mouse over the calendar to reproduce this.
My XAML -
<Grid x:Name="LayoutRoot">
<controls:DatePicker x:Name="dpTest"
Height="25"
Width="75"
SelectedDateChanged="DatePicker_SelectedDateChanged" />
</Grid>
My code behind -
Private Sub DatePicker_SelectedDateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
MessageBox.Show("Test Popup")
End Sub
Any ideas or workarounds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这实际上并不少见。我的一位同事最近在 Windows 窗体应用程序中遇到了非常奇怪的问题,因为他正在使用 MessageBox 来响应第三方菜单控件的单击事件(在菜单被关闭之前)。
一个建议对他不起作用,但可能会起作用对您来说,很好的工作是将呼叫“推送”给调度员。这样,您的 SelectedDateChanged 处理程序将在消息框实际显示之前返回。
但需要记住以下几点:
Hmm this is not all that uncommon actually. A coworker of mine recently ran into very strange issues in a Windows Forms application because he was using MessageBox in response to a third party menu control's click event (before the menu had been dismissed.)
One suggestion that didn't work for him but may very well work for you is to "push" the call onto the dispatcher. That way your SelectedDateChanged handler will return before the message box actually gets shown.
A couple of things to keep in mind though:
我在博客中发布了一个解决方法此处通过改变工作流程,不再需要消息框。
I blogged a workaround HERE that make the message box unnecessary by changing the work flow.