1

这是一个仅在窗口中显示阴影椭圆的测试应用程序。不管怎么写,椭圆的背景都是透明的;不是我设置 GeometryDrawing 的颜色。我难住了。结果图片显示椭圆的背景是透明的,而它应该是绿色的。

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:local="clr-namespace:WpfApp2"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="MainWindow"
        Background="Red"
        mc:Ignorable="d">
   <Window.Resources>
      <ResourceDictionary>
         <DrawingBrush x:Key="HatchBrush"
                       Stretch="UniformToFill"
                       TileMode="Tile"
                       Viewbox="0 0 10 10"
                       ViewboxUnits="Absolute"
                       Viewport="0 0 10 10"
                       ViewportUnits="Absolute">
            <DrawingBrush.Drawing>
               <GeometryDrawing Brush="Green">
                  <GeometryDrawing.Geometry>
                     <GeometryGroup>
                        <LineGeometry StartPoint="0 0"
                                      EndPoint="10 0" />
                        <LineGeometry StartPoint="0 0"
                                      EndPoint="0 10" />
                     </GeometryGroup>
                  </GeometryDrawing.Geometry>
                  <GeometryDrawing.Pen>
                     <Pen Brush="Yellow"
                          EndLineCap="Square"
                          StartLineCap="Square"
                          Thickness="3" />
                  </GeometryDrawing.Pen>
               </GeometryDrawing>
            </DrawingBrush.Drawing>
         </DrawingBrush>
       </ResourceDictionary>
   </Window.Resources>
   <Grid Margin="5"
         HorizontalAlignment="Stretch"
         VerticalAlignment="Stretch">
      <Ellipse x:Name="c_Ellipse"
               HorizontalAlignment="Stretch"
               VerticalAlignment="Stretch"
               Fill="{StaticResource HatchBrush}"
               Stroke="Black" />
   </Grid>
</Window>

这就是我得到的: 具有透明背景而不是指定的绿色的椭圆

椭圆的背景应该是绿色:

<GeometryDrawing Brush="Green">
4

1 回答 1

1

没有使用 GeometryDrawing 的填充Brush几何。

您可以使用 RectangleGeometry 而不是两个 LineGeometry:

<GeometryDrawing Brush="Green">
    <GeometryDrawing.Geometry>
        <RectangleGeometry Rect="0,0,10,10"/>
    </GeometryDrawing.Geometry>
    <GeometryDrawing.Pen>
        <Pen Brush="Yellow" Thickness="1.5"/>
    </GeometryDrawing.Pen>
</GeometryDrawing>
于 2020-08-17T21:35:06.307 回答