我为我的表单写了一种样式,一切看起来都很好,只是我的按钮上没有文字。我唯一能得到的就是一个没有内容的灰色按钮。
以下是我尝试过的:
<Style x:Key="CodeButton" TargetType="{x:Type Button}" >
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Content" Value="Enter"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border
Name="Border"
CornerRadius="4"
Padding="10"
BorderBrush="#666666"
Background="#e5e5e5"
BorderThickness="1">
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="#90c74b"/>
<Setter TargetName="Border" Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect Color="#90c74b" Direction="0" ShadowDepth="4" Opacity="0.7" Softness="0.8" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
正如您在第6行看到的那样,我希望按钮的内容是"Enter“。
发布于 2016-01-06 11:18:45
为了显示文本,您需要在模板中添加一个ContentPresenter
。
试试这个:
<Style x:Key="CodeButton" TargetType="{x:Type Button}" >
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Content" Value="Enter"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border
Name="Border"
CornerRadius="4"
Padding="10"
BorderBrush="#666666"
Background="#e5e5e5"
BorderThickness="1">
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="#90c74b"/>
<Setter TargetName="Border" Property="BitmapEffect">
<Setter.Value>
<DropShadowBitmapEffect Color="#90c74b" Direction="0" ShadowDepth="4" Opacity="0.7" Softness="0.8" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
https://stackoverflow.com/questions/34631757
复制相似问题