简体   繁体   English

按钮如何删除边框

[英]Button how to remove border

I have a question about dat wpf buttons. 我对dat wpf按钮有疑问。 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) 一切正常,但此按钮周围有一些小边框=(我尝试过BorderBrush="{x:Null}"但该边框再次出现。(如果MouseOver突出显示此边框)

As far as I understand it, a lot of WPF controls are fully defined in their styles. 据我了解,许多WPF控件的样式已完全定义。 So even if you specify a different border on a Button , for example; 因此,即使您在Button上指定了不同的边框,例如; the Button 's existing styles will override whatever you have specified. Button的现有样式将覆盖您指定的任何样式。 To overcome this, you must create a ControlTemplate . 为了克服这个问题,您必须创建一个ControlTemplate

    <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. 它将把每个BorderThickness或按钮内的每个Border设置为0。

slade is right, try modifying what you have to look more like the following and it should give you what you want. slade是正确的,请尝试修改您必须具有的外观,如下所示,它应该可以为您提供所需的东西。

<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>

Been a while since I did any "real" WPF, but does 自从我做过任何“真正的” WPF以来已经有一段时间了,但是

BorderThickness="0,0,0,0"

work? 工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM