English 中文(简体)
视窗8 度量: 有效使用
原标题:Windows 8 Metro: Implementing Validation

我只花了约2个小时,没有发现任何东西。

鉴于以下设想:

public class Person
{
    [Required]
    public string Name { get; set; }
}

XAML:

<TextBox Text="{Binding Name, Mode=TwoWay}" />

如MVC3一样,你将如何自动获得关于统一调查的反馈?

(Oh,如果我能够使用[要求]或(不)等综合数据年报,那么我确实不会 care。)

任何帮助都受到高度赞赏!

最佳回答

我在TextBoxValidationExtensions,并允许你界定这种确认:

<TextBox
    Width="400"
    HorizontalAlignment="Left"
    xyzc:TextBoxValidationExtensions.Format="NonEmptyNumeric"
    xyzc:TextBoxValidationExtensions.InvalidBrush="Red"
    xyzc:TextBoxValidationExtensions.ValidBrush="Green" />

表格目前的定义是:

[Flags]
public enum ValidTextBoxFormats
{
    Any = 0,
    NonEmpty = 1,
    Numeric = 2,
    NonEmptyNumeric = 3
}

The entire code is a bit too long to share here. You can take out the code from CodePlex and modify to your liking - add new validation rules, modify default brushes etc.

问题回答

如在<编码>文本箱/代码>上使用<代码>>>>>> 符号>,请在代码上写出一种功能,以进行所要求的验证。

根据框架所提供的支持,你关于“确定”案文领域的特殊想法似乎非常少见,而且很不寻常,它根本无需考虑。 我们都知道,如果你想要做的事情是共同的或有用的,那么在这样一个设计良好和全面的框架中就一定会考虑这种特点。





相关问题
How to bind a TabControl to an ObservableCollection in XAML

I have the following line of code in my code-behind class. TabControl.ItemsSource = ((MainWindowViewModel)DataContext).TabItemViewModels; I would like to move this to the XAML file. In brief, ...

Bind to ancestor of adorned element

Here is the case: <DataTemplate x:Key="ItemTemplate" DataType="local:RoutedCustomCommand"> <Button Command="{Binding}" Content="{Binding Text}" ...

FlowDocument Force a PageBreak (BreakPageBefore)

I m using C# to create a FlowDocument and fill it with data within a table. Example: FlowDocument flowDoc = new FlowDocument(); Table table1 = new Table(); flowDoc.Blocks.Add(table1); table1....

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF TreeView binding through XAML

So I have a class structure like this Store Owner Cashier List of Products Product Name Price List of Vendors Company Name Contact Name So there are 4 ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签