How to set DatePicker value equal yesterday in xaml in xamarin.form?

CondaConda Member ✭✭

To set the Date attribute in xaml equal today we can use Today attribute as following:

xmlns:system="clr-namespace:System;assembly=mscorlib"
<DatePicker Date="{x:Static system:DateTime.Today}"/>

I've tried to set it by using AddDays method but it couldn't help.

<DatePicker Date="{x:Static system:DateTime.Today.AddDays(-1)}"/> Does not work.

So is there a way?

Best Answer

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    But what's the point?
    I mean a Picker should be binded to a property - otherwise what's the point of it being a picker?
    <DatePicker Date="{x:Static helpers:DateTimeHelper.Yesterday}"/> is pretty much functionless as a Picker.
    If the user picks a date and that date doesn't go back to your ViewModel. So it might as have just been a Label if you're only wanting to display yesterday with it.

    I would expect it to be binded to a property. And the default value for the property starts as yesterday in the C#. Then it works as a Picker meaning you can actually pick a new date, while using the business rule you describe of starting it on yesterday.

Sign In or Register to comment.