testing
testing

Reputation: 20289

UpdateMode for DatePicker

I want to change the update mode like here. This is my code:

this.datePicker.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished);

The first part is marked as wrong this.datePicker.On<iOS>() and it is referencing an object in the xaml. On other places the same code is working fine. Don't know what's wrong here. The error message is:

Returns the platform-specific instance of this DatePicker, on which a platform-specific method may be called.

'IPlatformElementConfiguration' does not contain a definition for 'SetUpdateMode' and the best extension method overload 'Picker.SetUpdateMode(IPlatformElementConfiguration, UpdateMode)' requires a receiver of type 'IPlatformElementConfiguration'.

Any suggestion?

Edit:

It seems that the desired behavior (updateMode) is only available for Picker and not DatePicker. See here or here. Is there a way to enable the feature also for Datepicker? How?

Upvotes: 1

Views: 596

Answers (2)

Jammer
Jammer

Reputation: 10206

Using Xamarin Forms 4.6 here. Inside your custom renderer use this code:

protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
    base.OnElementChanged(e);

    if (e.NewElement != null && Control != null)
    {
        ...
        Element.On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUpdateMode(UpdateMode.WhenFinished);
        ...
    }
}

Upvotes: 1

bhavya joshi
bhavya joshi

Reputation: 1136

Sadly, UpdateMode is not available for Date picker.

And the workaround i found,is to create a custom calendar(which i did).Custom calendar looks tough to create,but is quite simple to implement(of basic functionalities) . With only 1 month of experience in xamarin, i've created it.

You can check out the complete code here:

https://medium.com/@bhavyajoshi2793/custom-calendar-in-xamarin-for-android-ios-windows-578f1136daec?source=friends_link&sk=9b1c97e0021da2e48ec84b5b6d4ff8e4

Upvotes: 1

Related Questions