Skip to main content

Microsoft Silverlight

Answered Question SL2 Toolkit March 2009 - TimePicker bug?RSS Feed

(0)

DJanjicek
DJanjicek

Participant

Participant

970 points

324 Posts

SL2 Toolkit March 2009 - TimePicker bug?

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
Ruurd Boeke

Participant

Participant

821 points

110 Posts

Microsoft

Re: SL2 Toolkit March 2009 - TimePicker bug?

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!

-- RJ (Ruurd Johan Boeke) [MSFT]
Silverlight
http://www.sitechno.com/blog

DJanjicek
DJanjicek

Participant

Participant

970 points

324 Posts

Re: Re: SL2 Toolkit March 2009 - TimePicker bug?

I'll do that...

Ruurd Boeke
Ruurd Boeke

Participant

Participant

821 points

110 Posts

Microsoft
Answered Question

Re: SL2 Toolkit March 2009 - TimePicker bug?

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           }

 Hope that helps.

-- RJ (Ruurd Johan Boeke) [MSFT]
Silverlight
http://www.sitechno.com/blog

DJanjicek
DJanjicek

Participant

Participant

970 points

324 Posts

Re: SL2 Toolkit March 2009 - TimePicker bug?

Excellent, It works works like a charme! Thanks a lot...

Gr.
Drazen

Ruurd Boeke
Ruurd Boeke

Participant

Participant

821 points

110 Posts

Microsoft

Re: SL2 Toolkit March 2009 - TimePicker bug?

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.

-- RJ (Ruurd Johan Boeke) [MSFT]
Silverlight
http://www.sitechno.com/blog

DJanjicek
DJanjicek

Participant

Participant

970 points

324 Posts

Re: SL2 Toolkit March 2009 - TimePicker bug?

"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...

Ruurd Boeke
Ruurd Boeke

Participant

Participant

821 points

110 Posts

Microsoft

Re: SL2 Toolkit March 2009 - TimePicker bug?

Hi DJanjicek,

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.

 

-- RJ (Ruurd Johan Boeke) [MSFT]
Silverlight
http://www.sitechno.com/blog

DJanjicek
DJanjicek

Participant

Participant

970 points

324 Posts

Re: SL2 Toolkit March 2009 - TimePicker bug?

thank you!

tabletpc
tabletpc

Member

Member

2 points

1 Posts

Re: SL2 Toolkit March 2009 - TimePicker bug?

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
Nedster657

Member

Member

48 points

63 Posts

Re: SL2 Toolkit March 2009 - TimePicker bug?

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?

Ruurd Boeke
Ruurd Boeke

Participant

Participant

821 points

110 Posts

Microsoft

Re: SL2 Toolkit March 2009 - TimePicker bug?

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.

-- RJ (Ruurd Johan Boeke) [MSFT]
Silverlight
http://www.sitechno.com/blog

Mauser
Mauser

Member

Member

3 points

2 Posts

Re: Re: SL2 Toolkit March 2009 - TimePicker bug?

 Hi Everybody!

That's my first post and I have emotions Confused

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,

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities