我希望文字以椭圆形显示。我目前的代码是:
<Button Grid.Column="2" Template="{StaticResource ThresholdBtnTemp}" Background="Green">
<TextBlock Text="0" Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Button>
<Button Grid.Column="3" Template="{StaticResource ThresholdBtnTemp}" Background="Yellow" />
<Button Grid.Column="4" Template="{StaticResource ThresholdBtnTemp}" Background="Red" Content="2" />
和
<ControlTemplate x:Key="ThresholdBtnTemp" TargetType="Button" >
<Ellipse Fill="{TemplateBinding Background}" Stroke="Black" Margin="2" />
</ControlTemplate>
红色和绿色都不会按照我的要求显示值。有什么建议吗?
答案 0 :(得分:0)
您需要更改controltemplate以“显示”其内容。尝试将ControlTemplate更改为:
<ControlTemplate x:Key="ThresholdBtnTemp" TargetType="Button" >
<Grid>
<Ellipse Fill="{TemplateBinding Background}" Stroke="Black" Margin="2" />
<ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>