I'm creating a program in C# using WPF that will generate a PDF of a sale sign for a retail store (just practice). Since it is a sale sign, I need the user to enter a date to represent the end of the sale. I'm using the datepicker control to do this. I would like to use some binding validation to check two things:
- A date is entered
- That date is either today or some point in the future
I'm somewhat new to C# and WPF, so I'll provide an example of the type of validation I'm using in case there are other ways to do it:
I also have text boxes that have functioning binding. Here is the xaxml for one of those text boxes:
<TextBox Name="title" Style="{StaticResource errorStyle}" Height="24" HorizontalAlignment="Stretch" Margin="6,8,6,0" VerticalAlignment="Top" Grid.Column="1">
<Binding Source="{StaticResource signData}" Path="SignTitle" UpdateSourceTrigger="Explicit">
<Binding.ValidationRules>
<ExceptionValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox>
And the corresponding class that models the data:
class SignOrder
{
...
public string SignTitle
{
get { return this.signTitle; }
set
{
if ( (String.IsNullOrWhiteSpace(value)) || (value.Length >= 20) )
{
throw new ApplicationException("Specify a title of less than 20 characters");
}
else
{
this.signTitle = value;
}
}
}
...
}
Do I need to create a converter class to work with the date? What would be the best way to validate the datepicker? What datatype is the value of the datepicker (string, int, date, ...)?
Thanks