I want to create a user control for getting a date from the user. It should have three textboxes, one for year, month and day. I don\'t know how to create it.
For starters stop copying and pasting :0). All your DP registrations are for the ValueProperty
. And you will have to handle the property changed callback for each property to update the Value property as well.
You don't have your text boxes wired up to your dependency property. The value is never set. You need some type of converter that will convert the values in your text boxes to an actual date too. I think you are better off going with the DatePicker
Control in the toolkit (3.5) or the framework (4.0).
Why not just use the Calendar
or DatePicker
controls in the WPF Toolkit? You haven't mentioned anything in your question that is custom, so this should work ok for you.
It might be better writing the logic kind of like this:
static void Main(string[] args)
{
Console.WriteLine("Year");
var year = Int32.Parse(Console.ReadLine());
Console.WriteLine("Month");
var month = Int32.Parse(Console.ReadLine());
Console.WriteLine("Day");
var day = Int32.Parse(Console.ReadLine());
var customDate = new DateTime(year, month, day);
Console.WriteLine(customDate);
Console.ReadLine();
}
You could implement something similar like having a button that when pressed will get the values and create a new datetime value. There are many ways of generating a DateTime from input values just surf the web and you will find a ton of examples and tutorials about this in WPF. Hopefully this will give you some idea's and help you out.