Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

iOS DateTime issue with Xamarin.Forms 4.2 and Prism?

$
0
0

Apparently if you update Xamarin Forms to the latest version, make a bindable DateTime property with Prism, and try to add time to it, it does not work anymore.

I have this Prism property MyDate:

private DateTime? _myDate;
public DateTime? MyDate
{
    get { return _myDate; }
    set { SetProperty(ref _myDate, value); }
}

Then I have a calendar where I bind the SelectedDate to MyDate:
<syncfusion:SfCalendar x:Name="calendar" SelectedDate="{Binding MyDate, Mode=TwoWay}" />

Then I have a button that is supposed to take the selected date, and add the current time, and print it using a label:
<Label Text="{Binding MyDateFormatted}"></Label>

private string _myDateFormatted;
public string MyDateFormatted
{
    get { return _myDateFormatted; }
    set { SetProperty(ref _myDateFormatted, value); }
}

// ...

private DelegateCommand _formatCommand;
public DelegateCommand FormatCommand =>
    _formatCommand ?? (_formatCommand = new DelegateCommand(ExecuteFormatCommand));

private void ExecuteFormatCommand()
{
    try
    {
        MyDate = MyDate.Value.Date.Add(DateTime.Now.TimeOfDay);
        MyDateFormatted = $"{MyDate.Value.ToLongDateString()} @ {MyDate.Value.ToShortTimeString()}";
    }
    catch (Exception)
    {
            // handle
    }
}

In android everything works. In iOS it does not add the current time to MyDate and it always shows 12am.

  • If instead of a Prism property I use a regular property such as public DateTime? MyDate { get; set; } it works in iOS too.
  • If instead of a calendar I set MyDate manually on page load, such as MyDate = DateTime.Today.Date and keep the Prism property, it works too.

I don't understand the problem. Is it a Prism property issue? A xamarin forms issue? A calendar issue?
Here's the repo to reproduce it in iOS.
https://github.com/stesvis/DateTimeTest

What does @BrianLagunas think? Could it be due to Prism and some incompatibility with the latest Xamarin Forms?
Thanks everybody


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>