P
P
postya2019-12-14 09:40:34
WPF
postya, 2019-12-14 09:40:34

How to remove the black stroke when hovering the mouse over a button?

There is a window in which there are two buttons, they have the same style. When you hover over the button, its background changes and the text color becomes black.
When you hover the mouse, an artifact pops out, an inner stroke, as if there are black borders inside the button itself.
Although I did not specify any stroke in the styles.
How can I get rid of this?
video

<Style x:Key="RoundedButton" TargetType="Button">
        <Setter Property="Grid.Column" Value="1"/>
        <Setter Property="Margin" Value="20 32"/>
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="FontSize" Value="14"/>
        <Setter Property="FontFamily" Value="Verdana"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border Name="RoundedButtonBorder"
                            CornerRadius="15"
                            Background="{TemplateBinding Background}"
                            BorderBrush="White"
                            Padding="30 7"
                            BorderThickness="2"
                            >
                        <ContentPresenter HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                         >
                        </ContentPresenter>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="White" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

<Button Content="OK"
                Click="SaveSettings"
                Style="{StaticResource RoundedButton}"
                Grid.Row="0" />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yuopi, 2019-12-17
@postya

You must either set the Border'u property

RenderOptions.EdgeMode="Aliased"
, but then the graphics are not about anything at all
Either draw the second border:
<Style x:Key="RoundedButton" TargetType="Button">
            <Setter Property="Grid.Column" Value="1"/>
            <Setter Property="Margin" Value="20 32"/>
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="FontFamily" Value="Verdana"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Background" Value="Transparent"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Border Name="RoundedButtonBorder"
                            Margin="0"
                            CornerRadius="15"
                            Background="{TemplateBinding Background}"
                            BorderBrush="White"
                            BorderThickness="3"
                            >
                                <ContentPresenter HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                         >
                                </ContentPresenter>
                            </Border>
                            <Border Name="RoundedButtonBorderHidden"
                            Margin="0"
                            CornerRadius="15"
                            BorderBrush="White"
                            BorderThickness="5"
                                    Visibility="Hidden"
                            >
                                <ContentPresenter HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                         >
                                </ContentPresenter>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="White" />
                                <Setter Property="Foreground" Value="Black" />
                                <Setter TargetName="RoundedButtonBorderHidden" Property="Visibility" Value="Visible"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question