Skip to content

Instantly share code, notes, and snippets.

@stewartsims
Created July 10, 2019 10:30
Show Gist options
  • Save stewartsims/248f7c8987aeed50d71f79934f85ae37 to your computer and use it in GitHub Desktop.
Save stewartsims/248f7c8987aeed50d71f79934f85ae37 to your computer and use it in GitHub Desktop.
UWP nullable / clearable date field adaptation
private void SetNullableText(DateField view)
{
if (view.NullableDate == null)
{
Control.DayVisible = false;
Control.MonthVisible = false;
Control.YearVisible = false;
}
else
{
Control.DayVisible = true;
Control.MonthVisible = true;
Control.YearVisible = true;
}
}
private void AddClearButton()
{
Control.AddHandler(DatePicker.RightTappedEvent, new RightTappedEventHandler(ClearDateHandler), true);
Control.AddHandler(DatePicker.PointerPressedEvent, new PointerEventHandler(TappedHandler), true);
}
private void TappedHandler(object sender, PointerRoutedEventArgs e)
{
var view = Element as DateField;
Control.DayVisible = true;
Control.MonthVisible = true;
Control.YearVisible = true;
}
private void ClearDateHandler(object sender, RightTappedRoutedEventArgs e)
{
var view = Element as DateField;
view.NullableDate = null;
Control.DayVisible = false;
Control.MonthVisible = false;
Control.YearVisible = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment