在silverlight中的椭圆上的文本

时间:2014-03-26 16:07:30

标签: silverlight text ellipse

我希望文字以椭圆形显示。我目前的代码是:

<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>

红色和绿色都不会按照我的要求显示值。有什么建议吗?

1 个答案:

答案 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>