我遗漏了一些东西,但我不明白是什么:
如果我这样做:
<ToggleButton Content="" FontFamily="Segoe MDL2 Assets" />按钮

按下后会发生这样的变化

但如果我使用模板更改它,它就会消失:
<ToggleButton>
<ToggleButton.Template>
<ControlTemplate>
<TextBlock Style="{StaticResource LargeIconStyle}" Text=""/>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>检查前:

检查后:

我不明白原因何在。你能帮帮我吗?选中按钮的颜色是系统按钮的颜色。
这些样式仅供您参考:
<Style
x:Key="LargeIconStyle"
BasedOn="{StaticResource BaseIconStyle}"
TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="32" />
</Style>
<Style x:Key="BaseIconStyle" TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="TextAlignment" Value="Center" />
</Style>发布于 2020-06-08 10:24:39
问题是您使用的是ControlTemplate和Template属性。它们用于控件的UI和功能。所以从本质上讲,你是在把你的控件变成一个TextBlock。
相反,您希望使用DataTemplate和ContentTemplate属性。
https://stackoverflow.com/questions/62247325
复制相似问题