I'm making an application where the user has to be more than 18. If he/she is less than 18 a messageBox
appears saying "under age". I'm using a datePicker
to select the users D.O.B. My problem is I'm not entirely sure on how to code this but I gave it a go by looking at tutorials but all the tutorials seem to be dateTimePickers
.
My code is as follows:
xaml
<DatePicker HorizontalAlignment="Center" Name="dpkDOB" Grid.Column="1" VerticalAlignment="Top" Grid.Row="1" />
xaml.cs
int age = DateTime.Today.Year - tbkDOB.Value.Year;
if (age < 18)
{
MessageBox.Show("Under age");
}