Requirement: When the user clicks on the TextView, a date picker should open up. The default date selected should be the date in the TextView. If the date is in the past, the DatePicker dialog's 'Set' button should be disabled. If the clickable TextView is empty, the default date in the DatePicker should be today's date.
相关问题
- Custom controls disabled. There was an internal is
- Xamarin. The name 'authorEntry does not exist
- Error:Xamarin.Forms targets have been imported mul
- Store data and global variables using the Applicat
- How to resize datepicker text programmatically
相关文章
- Woocommerce update shipping methods in checkout vi
- Xamarin form MessagingCenter Unsubscribe is not wo
- Reload data on tab selected in a fragment using vi
- jQuery UI datepicker - Trying to capture click eve
- The type initializer for 'SQLite.SQLiteConnect
- What to use for AttributeName in Xamarin Mac
- DatePickerDialog displays with two borders
- How to use native C++ libraries in Mono for Androi
This is a scenario I've already solved and am sharing here in order to help the Xamarin community. The code isn't very optimized, just FYI.
So, what we exactly need in this scenario is access to the event that the user is changing dates on the DatePicker Dialog. This can only be done if you use a DatePicker inside your own Dialog for more control. In my opinion, you cannot get access to this event if you use the default DatePickerDialog. Thus, we create a dialog extending the DialogFragment class and then implement the DatePicker inside of it. When the user clicks the TextView, we use show the fragment. Let's begin:
Here's the MainActivity:
Main.axml:
MDialogFragment.cs :
MDialogLayout.axml :