127 wpf transparency button
我正在尝试创建一个按钮,其中包含一个图像而没有边框 - 就像Firefox工具栏按钮,然后将鼠标悬停在它们上面并查看完整按钮.
我已尝试设置BorderBrushto Transparent,BorderThicknessto 0,并尝试过BorderBrush="{x:Null}",但您仍然可以看到按钮的轮廓.
Sim*_*mon 250
试试这个
<Button BorderThickness="0"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" >...
Run Code Online (Sandbox Code Playgroud)
Sne*_*hal 49
您可能需要更改按钮模板,这将为您提供一个没有框架的按钮,但也没有任何按下或禁用效果:
<Style x:Key="TransparentStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="Transparent">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
按钮:
<Button Style="{StaticResource TransparentStyle}"/>
Run Code Online (Sandbox Code Playgroud)
Alf*_*son 23
你要做的是这样的事情:
<Button Name="MyFlatImageButton"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
Padding="-4">
<Image Source="MyImage.png"/>
</Button>
Run Code Online (Sandbox Code Playgroud)
希望这是你想要的.
编辑:对不起,忘了提一下,如果你想在鼠标悬停在图像上时看到按钮边框,你所要做的就是跳过Padding =" - 4".
Nam*_* VU 20
我不知道为什么其他人没有指出这个问题与这个问题重复,并且接受了答案.
我在这里引用的解决方案:你需要重写ControlTemplate的Button:
<Button Content="save" Name="btnSaveEditedText"
Background="Transparent"
Foreground="White"
FontFamily="Tw Cen MT Condensed"
FontSize="30"
Margin="-280,0,0,10"
Width="60"
BorderBrush="Transparent"
BorderThickness="0">
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter Content="{TemplateBinding Content}"/>
</ControlTemplate>
</Button.Template>
</Button>
Run Code Online (Sandbox Code Playgroud)
您可能已经知道将 Button 放在 ToolBar 中会产生这种行为,但是如果您想要能够在所有当前主题中工作并具有任何可预测性的功能,则需要创建一个新的 ControlTemplate。
当 Button 具有焦点时,Prashant 的解决方案不适用于不在工具栏中的 Button。它也不能 100% 使用 XP 中的默认主题 - 当容器背景为白色时,您仍然可以看到微弱的灰色边框。
| 归档时间: |
|
| 查看次数: |
123901 次 |
| 最近记录: |