我剛剛搜索了約2小時,並沒有發現任何東西。Windows 8地鐵:實施驗證
考慮以下情形:
public class Person
{
[Required]
public string Name { get; set; }
}
XAML:
<TextBox Text="{Binding Name, Mode=TwoWay}" />
你會如何去自動獲得驗證的反饋對UI好像有在MVC3?
(哦,我真的不此刻關心,如果我將能夠使用集成DataAnnotations像[必需]與否)
任何幫助,非常感謝!
看來這是訣竅!無論如何,你能解釋我如何能夠在代碼而不是XAML中設置它嗎? – Shion
如果您使用的是MVVM,那麼您將擁有某種字段的視圖模型,並帶有Text和Format屬性,因此您只需設置像xyzc這樣的綁定:TextBoxValidationExtensions.Format =「{Binding Format}」。如果你只是在後面做代碼,那麼你會調用TextBoxValidationExtensions.SetFormat(myTextBox,ValidTextBoxFormats.Numeric)。 –
Jerry Nixon在他的博客中描述了另一種解決方案[這裏 - Let's Code!處理Windows應用商店中的驗證](http://blog.jerrynixon.com/2014/07/lets-code-handling-validation-in-your.html)。 –