Silverlight DatePicket 和 TimePicker 初始化
我正在使用工具包中的 DatePicker
和 TimePicker
。 我必须连接 SelectedDateChanged
事件,并且还要在代码中设置值。
我的问题是,当我初始化两个控件时,SelectedDateChanged
事件不会同步触发。 这对我来说是一个很大的问题,因为这意味着我初始化控件,一段时间后事件被触发并更改当前值(因为这就是我在事件处理程序中所做的)。
有什么解决办法吗? 我尝试监听一些在所有内容都初始化后触发的事件,但除了每个控件的 Loaded 事件之外没有任何其他事件(这真的很难看,每次控件所在的选项卡都会触发)活性)。
编辑:我的问题似乎消失了一段时间,所以我没有费心去调查它,以防它再次出现。 现在它做到了:(
我使用MVVM并在构造函数中初始化视图内的控件。然后,当VM获取视图时,它也会设置默认值。
不幸的是,当VM设置值时,控件还没有' t 被初始化并在一段时间后碰巧自己被初始化(即使我在构造函数中设置了它们)。
I'm using DatePicker
and TimePicker
from the toolkit. I've got to hook up on the SelectedDateChanged
event and I'm also setting the values in code.
My issue is that when I initialise both controls the SelectedDateChanged
event doesn't get fired synchronously. That's quite a big issue for me because it means I initialise the control and some time later the event gets fired and changes the current value (because that's what I do in the event handler).
Is there any work around? I tried to listen to some event that get fired once everything is initialized but there's nothing apart from the Loaded
event of each control (which is really ugly and gets fired each time the tab on which the controls are gets activated).
EDIT: my problem seemed to go away for a while so I didn't bother looking into it in case it came back. Now it did :(
I use MVVM and initialize the controls within the view in the constructor. Then, when the VM gets the view, it sets the default value as well.
Unfortunately, by the time the VM sets the value the controls haven't got initialized and happen to get themselves intialized some time later (even though I set them in the constructor). They then override the default values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
肯定有问题。 不过,我发现了一个非常简单的解决方法:如果我绑定控件并且不监听
SelectedDate
事件,我会同步获得更改,并且一切正常。我花了很长时间才弄清楚这一点,但现在它正在发挥作用。
There's definitely an issue. However I found a very easy workaround: if I bind the control and don't listen to the
SelectedDate
event I get the change synchronously and everything works fine.Took me ages to figure that out but now it's working.