简体   繁体   中英

Date Mask in textbox in windows phone 7.5 in C#

In windows phone 7.5 there is no date control ,I want to use date mask in text box and also validate false if user input wrong date . Please help me.

Thanks in Advance.

您可以使用DateTimePicker ,因此用户将只能选择有效日期。

you could create a DateTime variable like this

DateTime myValue = DateTime.Now;
myTextBlock.Text = myValue.ToString();

from here you could format it to the following if you like

Now what if you wanted to display only the Date and exclude the time? Luckily there are a number of methods available in the DateTime class which will enable you to display the date and/or time in a specific format. Let's have a look at these methods and the output they generate.

  1. myTextBlock.Text = myValue.ToShortDateString();

This statement displays only the Date in a short date format,ie, dd/mm/yyyy or mm/dd/yyyy depending upon phone's regional date time settings. Eg 03/01/2012

  1. myTextBlock.Text = myValue.ToShortTimeString();

In this statement we use the ToShortTimeString() method to display only the time. Eg 1:06 PM

  1. myTextBlock.Text = myValue.ToLongDateString();

In this statement the ToLongDateString() method displays the Day of the week followed by the Date in numbers, the Month in alphabets and the year in numbers. Eg Thursday, March 01, 2012.

use this link as a reference Working with DateTime Windows Phone 7.5

http://msdn.microsoft.com/en-us/library/ch92fbc1(v=vs.95).aspx

Try use TryParse method to know if string written to textbox can be converted to DateTime, if true then its valid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM