ghost1372 / HandyControls

Contains some simple and commonly used WPF controls based on HandyControl
https://ghost1372.github.io/
MIT License
1.07k stars 102 forks source link

hc:TextBox BorderBrush not work when validation error #202

Closed CodingOctocat closed 11 months ago

CodingOctocat commented 1 year ago

Describe the bug

I don't want the error message text, just the red outer box, so I set the error template to null:

<Style BasedOn="{StaticResource TextBoxPlusBaseStyle}"
       TargetType="{x:Type hc:TextBox}">
    <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
</Style>

HandyControl is as expected, but the HandyControls Border does not turn red brush.

NuGet package version

HandyControls (Custom version) 3.4.5

IDE

Visual Studio 2022

Framework type

.Net 7.0

Windows version

Windows 11 (22621)

Additional context

No response

ghost1372 commented 11 months ago

report it in original repo

CodingOctocat commented 11 months ago

I found the solution:

<Style x:Key="MyTextBoxStyle"
        BasedOn="{StaticResource TextBoxPlusBaseStyle}"
        TargetType="{x:Type hc:TextBox}">
    <Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Self}}" />
    <!--  Hide the validation error message, this solution does not work for ComboBox.  -->
    <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
    <Setter Property="b:TripleClickToSelectAllBehavior.Enabled" Value="True" />
    <Setter Property="hc:InfoElement.ShowClearButton" Value="{Binding IsReadOnly, Converter={StaticResource Boolean2BooleanReConverter}, RelativeSource={RelativeSource Mode=Self}}" />
    <Setter Property="hc:TitleElement.TitlePlacement" Value="Left" />

    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
            <Setter Property="ToolTip" Value="{Binding (Validation.Errors), RelativeSource={RelativeSource Self}, Converter={StaticResource ValidationErrorsToolTipConverter}}" />
        </Trigger>
    </Style.Triggers>
</Style>