How can I get rid of the border around the image embedded button?


Kylo

I am trying to get rid of the white border around the button. I am adding pictures to it Button. It doesn't seem to be the button itself, but the border of the image.

Here is the XAML,

   <Style x:Key="MyButton" TargetType="Button">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="border" BorderThickness="0" Background="{TemplateBinding Background}" CornerRadius="5" >
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Opacity" Value="0.5" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

and Buttonitself

   <Button Name="Button2" Content="stuff" Height="25" Grid.Column="1" Grid.Row="1"
          Style="{StaticResource MyButton}" Click="Button2_OnClick">
              <Button.Background>
                  <ImageBrush ImageSource="Images\ButtonEnterLight.png"></ImageBrush>
              </Button.Background>
   </Button>

The result is this

enter image description here

What else do I need to do to make it go away? It's been bugging me for the last week.

Edit: Here's a screenshot of the live visual tree, expanded to the first button with an image embedded in it.

enter image description here

Chris W

Well, so FocusVisualStyle is an often overlooked System.Windows.Style property value that in many cases adds resources that help visualize when a control has active focus.

In the template Styleyou're using , it might not always be obvious , since the default is empty static styles, but it's often also effective at runtime. So this often happens even if you have declared a "trigger" or "visual state" for the element in the template. Ghost borders or other visual effects appear on elements that are not explicitly set.

To fix this, you can do several things.

  • This property can be overridden globally .
  • This can be overridden on the template instance using a setter, e.g.<Setter Property="FocusVisualStyle" Value="{x:Null}"/>

    [The value can also effectively be Transparent, you just want to declare that you don't want BorderThickness to have color.

  • You can also discard the borders all together at the border by:BorderThickness="0"

However, the overall goal is to just process the properties, and FocusVisualStyleeither erase their result, or hide it, so it's no longer a visual and you can move on.

Hope this helps, cheers.

Related


How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How can I remove the border around the image?

username How can I remove the border around the square? Exterior: my HTML: <input id="black" type="image" src="html5-canvas-drawing-app/images/color-swatch-brown.png" onClick="changeColorBlack()"> my css: #black{ border:none; outline:none; background:none; pa

How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How to get rid of white space around image border

Zeid Khan I would like to make the image completely on the top right of the screen. body{ font-family: 'Roboto', sans-serif; font-weight: 300; background: #822B2B; color: #ffffff; overflow: hidden; } #showcase{ display: flex; justify-content: center; align-i

How can I get rid of the white outline around the button?

GlaciemTech How can I get the white outline from this button? It's CSS, let me know if you think it's caused by something. .btn { background: linear-gradient(45deg, rgba(51, 197, 230, 0.5) 0%,rgba(51, 230, 131, 0.5) 50%,rgba(108,0,153,0.65) 100%); border-r