如何用纯色和文本填充GeometryDraw

时间:2019-06-05 18:41:30

标签: wpf xaml

我有一个圆形的几何图形。

之前,当我不需要文本时,我用[control name] .brush = color填充了它。效果很好,但是我无法在圈子中添加文字(如果您知道这种方式,请告诉我)。

现在,我在Geometry.brush内放置一个带有文本块的可视画笔,并设置文本块的背景颜色。问题是它不能填满我的所有圆(只是一个正方形),当我不输入文字时,它不会给圆上色。

任何帮助,我们将不胜感激。我的代码如下。

谢谢

<GeometryDrawing x:Name="Part0">
    <GeometryDrawing.Pen>
        <Pen Brush="Black" Thickness="5"/>
    </GeometryDrawing.Pen>
    <GeometryDrawing.Brush>
        <VisualBrush Stretch="None">
            <VisualBrush.Visual>
                <Viewbox HorizontalAlignment="Center" VerticalAlignment="Center">
                    <TextBlock x:Name="tb0" Text="0%" FontSize="50" Foreground="Black"/>
                </Viewbox>
            </VisualBrush.Visual>
        </VisualBrush>
    </GeometryDrawing.Brush>
    <GeometryDrawing.Geometry>
        <PathGeometry>
            <PathFigure x:Name="pf0" StartPoint="0.001,0">
                <PathFigure.Segments>
                    <LineSegment x:Name="lg0" Point="1,1"/>
                    <ArcSegment x:Name="as0" Point="0,0" IsLargeArc="True" SweepDirection="Clockwise" Size="200,200"/>
                    <LineSegment x:Name="lg0_1" Point="1,1"/>
                </PathFigure.Segments>
            </PathFigure>
        </PathGeometry>
    </GeometryDrawing.Geometry>
</GeometryDrawing>

0 个答案:

没有答案
相关问题