如何使用xaml在DrawingImage中重用静态GeometryDrawing

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用xaml在DrawingImage中重用静态GeometryDrawing相关的知识,希望对你有一定的参考价值。

如果我在app.xaml中定义一个像这样的GeometryDrawing:

<GeometryDrawing x:Key="ReuseThis" 
    Pen="..." 
    Brush="..." 
    Geometry="..."/>

我怎样才能在以后的DrawingImage中使用它:

<DrawingImage x:Key="FullImage">
    <DrawingImage.Drawing>
        <DrawingGroup>
            <GeometryDrawing reuse it here somehow"{StaticResource ReuseThis}"/>
            <Geometrydrawing ...>
            <Geometrydrawing ...>
           </DrawingGroup>
      </DrawingImage.Drawing>
 </DrawingImage>

我试图避免在我的一堆DrawingImages中复制和粘贴GeometryDrawing。

谢谢

答案

您可以在XAML对象元素语法中使用StaticResource Markup Extension

<DrawingImage>
    <DrawingImage.Drawing>
        <DrawingGroup>
            <StaticResource ResourceKey="ReuseThis"/>
            <GeometryDrawing .../>
        </DrawingGroup>
    </DrawingImage.Drawing>
</DrawingImage>

以上是关于如何使用xaml在DrawingImage中重用静态GeometryDrawing的主要内容,如果未能解决你的问题,请参考以下文章