在xaml中绘制一个椭圆形框架

时间:2014-05-27 05:33:31

标签: .net silverlight xaml

我需要以圆圈形式显示数字。这是可行的,但有2或3位数时问题就开始了。预期会发生的是圆应该变成椭圆。如何在xaml中写椭圆。椭圆本身可以显示为circle.how以椭圆形式设置文本吗?

1 个答案:

答案 0 :(得分:1)

我过去曾经使用过这个TextBoxStyle来给我一些圆角,对它进行一些修改,就像我在这里做的那样可能会给你一些可能有效的东西或给你一些想法。看看这样的东西是否适合你。

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication24" x:Class="WpfApplication24.MainWindow"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="MinHeight" Value="50"/>
        <Setter Property="MaxHeight" Value="50"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="Padding" Value="4"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Border SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="90,90,90,90">
                        <ScrollViewer SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="PART_ContentHost" HorizontalAlignment="Center"  VerticalAlignment="Center"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
      <TextBox Style="{StaticResource TextBoxStyle }" BorderBrush="Black" BorderThickness="2" HorizontalContentAlignment="Stretch"  Text="12345" />
</Grid>

enter image description here