开发者

Default Validation Template not getting fired in WPF

My code goes as follows :

<TextBox >
    <TextBox.Text>
        <Binding Path="SaveAsText" ValidatesOnDataErrors="True" ValidatesOnExceptions="True" UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <val:SaveTextValidator></val:SaveTextValidator>
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
    <TextBox.Style>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip"
    Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                    Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/>开发者_JAVA技巧;
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

Now when a validation error happens, the ToolTip is getting displayed but the default validation template of making a TextBox border red is not firing !!

Where am I going wrong?


You are overwriting the default style of the TextBox (basically saying: do nothing unless I tell you to).

I imagine there is some trigger in the default style that makes the border red. Either implement it your self or base your style on the current default.

<Style BasedOn={x:Type TextBox} ...>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜