I have added a date picker in my Xamarin forms page. The issue I'm facing is on initial page load the size that the date picker occupies in the screen doesn't get resized on changing the date, if I select a date where text length is more than what was selected before.
Say for Example, If I had selected the date 21-May-2018 initially and If I change the date to 21-November-2018, now since the text length has increased the full text is not shown on the screen.
Please let me know how can I fix this issue.
XAML:
<StackLayout Style="{StaticResource layoutListItem}">
<Label Style="{StaticResource labelStandard}" Text="From" HorizontalOptions="Start" />
<DatePicker Date="{Binding FromDateFilter}" TextColor="#777777" VerticalOptions="CenterAndExpand"
HorizontalOptions="EndAndExpand" MaximumDate="{Binding ToDateFilter}">
<DatePicker.Format>dd-MMMM-yyyy</DatePicker.Format>
<DatePicker.Effects>
<effects:EntryNoBorderEffect />
</DatePicker.Effects>
</DatePicker>
</StackLayout>
Initial Load: (Date Range -> From : 29-may-2017)
On change: (Date Range -> From: 29-november-2017)
For those who are still waiting for a fix even on version Xamarin.Forms 5.0.0.2012
, here's a workaround:
Extend Xamarin.Forms.DatePicker
and call InvalidateMeasure
whenever the date changes:
public class FixedDatePicker : DatePicker
{
public FixedDatePicker()
{
DateSelected += FixedDatePicker_DateSelected;
}
private void FixedDatePicker_DateSelected(object sender, DateChangedEventArgs e)
{
InvalidateMeasure();
}
}
Use this extended class instead of the default in your XAML.
I hope that the Xamarin team fixes this bug soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With