1

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)

H.B.
  • 166,899
  • 29
  • 327
  • 400
Papa John
  • 3,764
  • 3
  • 26
  • 23
  • Have you tried setting `BorderThickness="0"` and `BorderBrush="Transparent"`? – Grant Thomas Dec 21 '11 at 13:57
  • Try to override the Controltemplate of the button and remove this border or trigger it differently on mouse over if needed. – WPF-it Dec 21 '11 at 13:57
  • Issues like this are better investigated when you show a screenshot of the problematic area. – Sergey Kalinichenko Dec 21 '11 at 14:01
  • this exact question has been asked here: http://stackoverflow.com/questions/2899948/get-rid-of-button-border-in-wpf – Adam Dec 21 '11 at 14:05
  • Did you try that: http://stackoverflow.com/questions/4117891/removing-the-focus-frame-box-from-controls ? –  Dec 21 '11 at 14:19

4 Answers4

3

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.

Samuel Slade
  • 8,405
  • 6
  • 33
  • 55
  • Styles accept changes to their properties being applied, however - so you can still change aesthetics of a control without having to completely rewrite a full style or template; granted, some of the brushes, etc. might be used regardless of specifications. – Grant Thomas Dec 21 '11 at 14:00
  • Aye, but the `Button` in particular is essentially over specified in that a lot of the triggers will override any custom styling - i.e. when hovering the mouse over the `Button`. – Samuel Slade Dec 21 '11 at 14:02
  • Agreed. For this specific problem, though, I'm sure the solution should be more straightforward. – Grant Thomas Dec 21 '11 at 14:04
  • 1
    this is actually true for a lot of basic controls like the button or checkbox. more often than not, especially when you have something simple in mind the template is easier – tam Dec 21 '11 at 14:04
2
    <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.

Louis Kottmann
  • 16,268
  • 4
  • 64
  • 88
1

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>
tam
  • 1,583
  • 2
  • 13
  • 25
0

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

BorderThickness="0,0,0,0"

work?

ZombieSheep
  • 29,603
  • 12
  • 67
  • 114
  • I just tried this in Kaxaml, and it doesn't make any difference -- it looks like Button's template ignores BorderThickness. – Joe White Dec 21 '11 at 14:03