Created
July 10, 2019 10:30
-
-
Save stewartsims/248f7c8987aeed50d71f79934f85ae37 to your computer and use it in GitHub Desktop.
UWP nullable / clearable date field adaptation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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