Duration picker

Ben.2646Ben.2646 USMember ✭✭

Hi,

Is there a way to set up a duration input in Xamarin Forms ? I would like to allow the user to enter a simple duration.
Example:
"How many time did you run today?"
"01:12:58" <--- I woul like this kind of input

THanks !

Tagged:

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @Ben.2646

    Looks like a TimePicker to me.
    https://developer.xamarin.com/api/type/Xamarin.Forms.TimePicker/

    Once they set a time, you can convert that to a duration in your code. 1:12:58 am becomes a duration of 1 hour, 12min, 58 seconds.

  • Ben.2646Ben.2646 USMember ✭✭

    The problem is that the TimePicker looks like that:

    It's not very usefull to enter a duration.

  • BradCunninghamBradCunningham USBeta, Developer Group Leader ✭✭

    Did you ever come up with a solution to this one? I have a similar need. I need the user to select a duration say "1 hour 15 minutes"

  • ChristianDaniel.9282ChristianDaniel.9282 USMember ✭✭

    Would be interested in a nice solution too. I've the same use case. I need to specify a durations with a resolution of one minutes.

  • JohnHardmanJohnHardman GBUniversity mod

    @ChristianDaniel.9282 said:
    Would be interested in a nice solution too. I've the same use case. I need to specify a durations with a resolution of one minutes.

    It's either a case of a custom control with renderers for each target platform, or side-by-side ListViews as per the post by @ClintStLaurent above. I currently use the former, but I might switch to the latter at some point in future.

  • ChristianDaniel.9282ChristianDaniel.9282 USMember ✭✭

    I created some Pickers Side By Side, but with Xamarin.Forms for Android, I get several issues when trying to implement a comfortable solution. E.g. I wanna define a maximum Duration. So I need to change the count of minutes the user can choose in dependency of the selected hours. But it's crashing when exchanging the Collection of ints bound to the picker (ArgumentOutOfRange). I'm pretty sure I'll find a solution to those behaviors, but it would be some much easier with a nice control that handle such cases automatically.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @ChristianDaniel.9282 said:
    But it's crashing when exchanging the Collection of ints bound to the picker (ArgumentOutOfRange). I'm pretty sure I'll find a solution to those behaviors,

    That's not their problem. That sounds like bad code on your part.
    What does this error mean and how do I fix it?

  • ChristianDaniel.9282ChristianDaniel.9282 USMember ✭✭

    @ClintStLaurent said:

    @ChristianDaniel.9282 said:
    But it's crashing when exchanging the Collection of ints bound to the picker (ArgumentOutOfRange). I'm pretty sure I'll find a solution to those behaviors,

    That's not their problem. That sounds like bad code on your part.
    What does this error mean and how do I fix it?

    Oh, it is! When a Usercontrol is bound to an observable Datasource, it should handle Data exchange well. For example when the Itemssource (ObservableCollection) is cleared e.g. a Picker Control should handle that without throwing exceptions. As it does in other XAML/Binding concepts like UWP, Silverlight, .....

Sign In or Register to comment.