开发者

DrawingBrush used as the Fill for a Rectangle

I have the below definition for a DrawingBrush. It is an exmaple I found online that draws an arrow:

<DrawingBrush x:Key="arrow" Stretch="Uniform">
  <DrawingBrush.Drawing>
    <DrawingGroup>
      <DrawingGroup.Children>
        <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 358.447,332.449L 358.447,319.664L 380.875,319.664L 380.798,309.408L 407.698,326.505L 381.068,343.628L 380.982,332.45L 358.447,332.449 Z "/>
      </DrawingGroup.Children>
    </DrawingGroup>
  </DrawingBrush.Drawing>
</DrawingBrush>

Now, I created a rectangle on my Canvas and set the rectangle's Fill property to the above DrawingBrush:

<Rectangle Fill="{DynamicResource arrow}" Stroke="#FF000000" Width="Auto" Height="Auto" Canvas.Top="339.815" Canvas.Left="112.037" x:Name="arrowRectangle"/>

With the rectangle's Width and Height set to "Auto", I expected the rectangle to resize to automatically display the arrow that is drawn. However, it seems that I need to expli开发者_Python百科citly set a Width/Height in order to see anything. If I leave the Width/Height as Auto, the rectangle is displayed as a single point, as if Width = Height = 0.

It seems that I am misunderstanding how the DrawingBrush works. I am just looking for a way to display an arrow. Would I have to use an Image instead of a DrawingBrush? I looked for a DrawingBrush first because I thought for such a simple thing as an arrow it would work fine.

Thanks.


DrawingBrush is just another brush, which doesnt have layout sizing, so it will just try to fill the area of the control in which it is called. So you cant expect brush controlling the Rectangle sizing. But you can use a Path with this Geometry as DataProperty

<Path Fill="Red" Data="F1 M 358.447,332.449L 358.447,319.664L 380.875,319.664L 380.798,309.408L 407.698,326.505L 381.068,343.628L 380.982,332.45L 358.447,332.449 Z " Stretch="Uniform" ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜