<textInputLayout:SfTextInputLayout Hint="{x:Static resources:AppResources.DateStart}" Grid.Column="0"> <controls:NullableDatePicker NullableDate="{Binding StartDate}"/ Placeholder=""> textInputLayout:SfTextInputLayout>
<StackLayout Orientation="Vertical"> <textInputLayout:SfTextInputLayout Margin="20" Hint="{StaticResource Key=startDate}" > <local:NullableDatePicker NullableDate="{Binding MyDate}" PlaceHolder=""/> </textInputLayout:SfTextInputLayout> <Button Text="Show selected date" Clicked="Button_OnClicked"/> </StackLayout>
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
// Check if the property we are updating is the format property
if (e.PropertyName == Xamarin.Forms.DatePicker.DateProperty.PropertyName || e.PropertyName == Xamarin.Forms.DatePicker.FormatProperty.PropertyName)
{
var entry = (NullableDatePicker.Controls.NullableDatePicker)this.Element;
var parent = ((this.Element.Parent as Grid).Parent as StackLayout).Parent as SfTextInputLayout;
MethodInfo method = parent.GetType().GetMethod("UpdateText", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(parent, new object[] { entry.Date.ToString() });
// If we are updating the format to the placeholder then just update the text and return
if (this.Element.Format == entry.PlaceHolder)
{
this.Control.Text = entry.PlaceHolder;
return;
}
}
base.OnElementPropertyChanged(sender, e);
} |
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
// Check if the property we are updating is the format property
if (e.PropertyName == Xamarin.Forms.DatePicker.DateProperty.PropertyName || e.PropertyName == Xamarin.Forms.DatePicker.FormatProperty.PropertyName)
{
var entry = (NullableDatePicker.Controls.NullableDatePicker)this.Element;
var parent = ((this.Element.Parent as Grid).Parent as StackLayout).Parent as SfTextInputLayout;
MethodInfo method = parent.GetType().GetMethod("UpdateText",
BindingFlags.NonPublic | BindingFlags.Instance);
if (entry.NullableDate == null)
{
method.Invoke(parent, new object[] { string.Empty });
}
else
{
method.Invoke(parent, new object[] { entry.Date.ToString() });
}
// If we are updating the format to the placeholder then just update the text and return
if (this.Element.Format == entry.PlaceHolder)
{
this.Control.Text = entry.PlaceHolder;
return;
}
}
else if (e.PropertyName == NullableDatePicker.Controls.NullableDatePicker.NullableDateProperty.PropertyName)
{
var entry = (NullableDatePicker.Controls.NullableDatePicker)this.Element;
if (entry.NullableDate == null)
{
var parent = ((this.Element.Parent as Grid).Parent as StackLayout).Parent as SfTextInputLayout;
MethodInfo method = parent.GetType().GetMethod("UpdateText",
BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(parent, new object[] { string.Empty });
}
}
base.OnElementPropertyChanged(sender, e);
} |
Hi sir @Sridevi Sivakumar, i tried using this code, but instead of date picker, i used time picker. Upon updating the time, i get this error message. Same error with the condition if the entry.NullableTime is not null
Was able to fix the error, added parameter on method.Invoke
method.Invoke(parent, new object[] { string.Empty , false });
We are glad to know
that the reported problem has been resolved at your end, and thanks for your valuable
suggestions. Please let us know if you have any further queries on this. We are
happy to help.