Wpf custom datepicker user control

后端 未结 4 1976
执念已碎
执念已碎 2021-01-27 17:03

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.

         


        
相关标签:
4条回答
  • 2021-01-27 17:16

    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.

    0 讨论(0)
  • 2021-01-27 17:23

    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).

    0 讨论(0)
  • 2021-01-27 17:30

    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.

    0 讨论(0)
  • 2021-01-27 17:34

    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.

    0 讨论(0)
提交回复
热议问题