0

I tried the following way to extend style and add tooltip message if validationresult is true. But it shows error "Property style is set more than once". How can I extend style for this case. Any help will be appreciated. Thanks.

<TextBox Width="500" Style="{StaticResource HasInvalidValue}">
                <TextBox.Text>
                    <Binding Path="Text" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <Validator:PathFormatValidationRule/>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox.Text>
                <TextBox.Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource HasInvalidValue}">
                    <Style>
                        <Setter Property="ToolTip" Value="Enter Text."/>
                    </Style>
                </TextBox.Style>
            </TextBox>

And the style is defined as:

<Style x:Key="HasInvalidValue" TargetType="{x:Type TextBox}">
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="true">
            <Setter Property="Background" Value="White"/>
            <Setter Property="ToolTip"
          Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                          Path=(Validation.Errors)[0].ErrorContent}"/>
        </Trigger>
    </Style.Triggers>
</Style>
4

1 回答 1

2

首先是设置在

<TextBox Style="{StaticResource HasInvalidValue}" ...
...
</TextBox>

接着

<TextBox.Style ...
</TextBox.Style>

从文本框元素中删除样式属性。

于 2013-06-11T06:58:04.400 回答