为什么我的按钮样式不显示按钮内容? [英] why my Button Style not Show Button content?
本文介绍了为什么我的按钮样式不显示按钮内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我的按钮样式不显示按钮内容?
你好
我为按钮创建简单样式,并使用ContentPresenter显示我的按钮内容.但是按钮内容不显示.
why my Button Style not Show Button content?
Hello
I Create simply style for button and use ContentPresenter to display My Button Content.But buttoncontent not display.
<Style x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" >
<Grid>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Content"/>
<Rectangle RadiusX="5" RadiusY="5">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF7C3030" Offset="0" />
<GradientStop Color="#FF271D1D" Offset="1" />
<GradientStop Color="#FF450404" Offset="0.484" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="White"/>
</Style>
<Button Grid.Row="1" Grid.Column="1"
Content="ShowWindow" Style="{StaticResource btnStyle}"
Foreground="White" FontSize="20"/>
推荐答案
将ContentPresenter放在矩形之后,因为矩形会覆盖它,因为它的zindex会更高.
Put your ContentPresenter after the rectangle, as the rectangle will overwrite it, as its zindex will be implied higher.
这篇关于为什么我的按钮样式不显示按钮内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文