WPF C# Text box with hour string format
How to make that user can only input h开发者_Python百科our format in text box for example HH:MM?
Depending on strictness of requirements you may want to create a specific behaviour that will be attached to KeyDown
event and disable keys other than currently accepted given format and current text input position in (HH:MM), you could even think of different ways to guarantee automatic :
input by your behaviour if you want to be limited by textbox control for time input.
you can get some inspiration here I think numeric only behaviour example
Look at Binding.StringFormat. It allows for conversion to DateTime
or TimeSpan
while specifying a certain string format to define how the user inputs the value, and how the value is displayed.
It sounds like you are looking for a masked text box.
You can fine one on codeplex here...
WPF Toolkit
EDIT. There is also a datetimeupdown control. Which might be nearer to what you want.
精彩评论