Papa John
Papa John

Reputation: 3784

Button how to remove border

I have a question about dat wpf buttons. In my app I have fore example some code

<Button x:Name="SukaKnopka" VerticalAlignment="Top" HorizontalAlignment="Right" Background="Black" MaxHeight="20" MaxWidth="20" BorderBrush="Black">
    <Image Source="ButtonsImages/close_btn.png" Stretch="Fill"/>
</Button>

All is fine but there is some little border around this button =( I have tryed BorderBrush="{x:Null}" but the border again present. (This border highlights if MouseOver)

Upvotes: 1

Views: 4971

Answers (4)

Louis Kottmann
Louis Kottmann

Reputation: 16618

    <Button>
        <Button.Resources>
            <Style TargetType="Border">
                <Setter Property="BorderThickness" Value="0" />
            </Style>
        </Button.Resources>
    </Button>

This should do the trick. It will set every BorderThickness or every Border inside the button to 0.

Upvotes: 2

tam
tam

Reputation: 1583

slade is right, try modifying what you have to look more like the following and it should give you what you want.

<Button x:Name="SukaKnopka" VerticalAlignment="Top" HorizontalAlignment="Right" Background="Black" MaxHeight="20" MaxWidth="20" BorderBrush="Black">
<Button.Template>
    <ControlTemplate>
            <Image Source="ButtonsImages/close_btn.png" Stretch="Fill"/> 
    </ControlTemplate>
</Button.Template>
</Button>

Upvotes: 1

Samuel Slade
Samuel Slade

Reputation: 8613

As far as I understand it, a lot of WPF controls are fully defined in their styles. So even if you specify a different border on a Button, for example; the Button's existing styles will override whatever you have specified. To overcome this, you must create a ControlTemplate.

Upvotes: 3

ZombieSheep
ZombieSheep

Reputation: 29953

Been a while since I did any "real" WPF, but does

BorderThickness="0,0,0,0"

work?

Upvotes: 0

Related Questions