Проверка WPF DataBinding проигнорирована

Я (полагаю), что обеспечиваю электричеством Проверку DataBinding способом учебника, но она просто не работает - вообще.

В отладчике, Validate(object value, CultureInfo cultureInfo) метод никогда не называют.

Что дает? Кроме того, для бонусных очков любые указатели при отладке WPF были бы потрясающими.

Я отправляю свой XAML и рассматриваемый класс

<UserControl x:Class="FooControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:Foo.Controls"
         mc:Ignorable="d" 
         d:DesignWidth="300">
<Grid Name="GridFoo">
    <Grid.Resources>
        <local:ValueConverter x:Key="MyConverter" />
    </Grid.Resources>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <TextBox Name="TextBoxScalar" Grid.Column="0" TextAlignment="Right">
        <TextBox.Text>
            <Binding Mode="OneWay" Path="Scalar" NotifyOnValidationError="True" ValidatesOnDataErrors="True" ValidatesOnExceptions="True">
                <Binding.ValidationRules>
                    <local:ScalarValidationRule />
                </Binding.ValidationRules>
            </Binding>
        </TextBox.Text>
    </TextBox>
    <TextBlock Name="TextBlockUnit" Grid.Column="1" TextAlignment="Left" Padding="3">
        <Hyperlink>
            <!-- Use a custom converter here b/c generics break wpf... -->
            <Run Text="{Binding Mode=OneWay, Path=Unit, Converter={StaticResource MyConverter}}" />
        </Hyperlink>
    </TextBlock>
</Grid>

ValidationRule

public class ScalarValidationRule : ValidationRule
{
    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        string number = value as string;
        double d;
        return new ValidationResult(Double.TryParse(number, NumberStyles.Any, cultureInfo, out d),
            String.Format("\"{0}\" is not a number.", number));
    }
}
5
задан pomeroy 20 July 2010 в 20:29
поделиться