Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit SL2 Toolkit March 2009 - TimePicker bug?
12 replies. Latest Post by Mauser on April 30, 2009.
(0)
DJanjicek
Participant
970 points
324 Posts
03-23-2009 9:34 AM |
Hey everybody,
i'm using the march version of SL2 toolkit and i think there is a bug in the timepicker control. The initial value is not being displayed in the textbox, but the control definately contains the value. Am I doing something wrong?
Thanks in advance...
Ruurd Boeke
821 points
110 Posts
03-23-2009 12:22 PM |
Confirmed. There is something in the TimePicker keeping the value from going into TimeUpDown.
I will create a bug report for this.In the meantime, you could use TimeUpDown instead of TimePicker.
Thanks!
03-23-2009 12:28 PM |
I'll do that...
03-23-2009 12:41 PM |
Hi DJanjicek,
I've looked into this some more, and the reason behind this is that the value is being set by the xaml parser before the control has been loaded. So, another workaround would be to make sure it is reset after it has been loaded.
Subscribe to the loaded event of your TimePicker and use this code in the eventhandler:
1 private void TimePicker_Loaded(object sender, RoutedEventArgs e)2 {3 Dispatcher.BeginInvoke(() =>4 {5 DateTime? value = tp.Value;6 7 tp.Value = null;8 tp.Value = value;9 });10 }
03-23-2009 1:01 PM |
Excellent, It works works like a charme! Thanks a lot...
Gr.Drazen
03-23-2009 4:15 PM |
I've opened a codeplex issue so you can track it: http://silverlight.codeplex.com/WorkItem/View.aspx?WorkItemId=2358
Again, thanks for reporting this.
03-23-2009 4:22 PM |
"When setting a value in xaml, the TimePicker does not show it in the TextBox, as reported here: http://silverlight.net/forums/t/83044.aspx"
By the way, this issue also appears when setting the value property in code-behind, actually that's where i had the biggest problems...
03-23-2009 4:42 PM |
I am able to set a value from a button eventhandler like so:
1 private void SetValueOnTP(object sender, RoutedEventArgs e) 2 { 3 tp.Value = DateTime.Now; 4 }
I suspect you are setting the value before the control has completed loading, for instance in the constructor. I was able to reproduce that.The workaround is unchanged: you need to make sure to set your value after the control has been loaded. For instance by subscribing to the loaded event and resetting the value.
I would like to offer another workaround: you could modify our source code and insert a line of code inside TimePicker.cs:
1 internal TimeUpDown TimeUpDownPart 2 { 3 get { return _timeUpDownPart; } 4 set 5 { 6 if (_timeUpDownPart != null) 7 { 8 _timeUpDownPart.ValueChanged -= TimeUpDownValueChanged; 9 _timeUpDownPart.Parsing -= TimeUpDownParsing; 10 _timeUpDownPart.ParseError -= TimeUpDownParseError; 11 } 12 _timeUpDownPart = value; 13 if (_timeUpDownPart != null) 14 { 15 PropagateNewValue(); 16 _timeUpDownPart.ValueChanged += TimeUpDownValueChanged; 17 _timeUpDownPart.Parsing += TimeUpDownParsing; 18 _timeUpDownPart.ParseError += TimeUpDownParseError; 19 } 20 } 21 }
Line 15 has been added and should solve your issues.
03-24-2009 11:22 AM |
thank you!
tabletpc
Member
2 points
1 Posts
04-04-2009 6:04 PM |
Thanks so much for this workaround!
I had been trying to overcome this behaviour for several hours and I was not sure if I was doing something wrong or if this was a "designed in" behaviour.
I made a slight modification to your solution which I hope will fix all TimePickers in use:
private void AnyTimePicker_Loaded(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(() => { DateTime? value = ((TimePicker)sender).Value; ((TimePicker)sender).Value = null; ((TimePicker)sender).Value = value; });
}
Nedster657
48 points
63 Posts
04-16-2009 4:03 AM |
Just to follow up on this, the issue still exhibits itself when setting the TimePicker value programmatically even post load. Any ideas on a fix timeframe?
04-16-2009 12:15 PM |
In this thread I've shown the code change needed for the fix. I would suggest making the change yourself until our next release. I'm sorry, but I don't have a timeframe for that yet.
Mauser
3 points
2 Posts
04-30-2009 8:29 AM |
Hi Everybody!
That's my first post and I have emotions
I would like to use the ValueChangin event of the TimePicker, because I use binding to the TimePicker, but I want to catch if somebody changing the value from the interface.
How can I catch the interaction from the interface? I used GotFocus, but this event fires always ... I don't know why.
I can't catch the MouseLeftButtonDown...
Thanks,