在画布中显示DrawingBrush并保持其比例

时间:2012-09-11 08:44:25

标签: wpf xaml svg drawingbrush

我使用SharpVector将icon.svg转换为icon.xaml。 该程序生成一个DrawingBrush,如:

<DrawingBrush x:Key="Plus">
<DrawingBrush.Drawing>
    <DrawingGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <DrawingGroup x:Name="DrawingLayer">
        <DrawingGroup.ClipGeometry>
          <RectangleGeometry Rect="0,0,88.582672,88.582672" />
        </DrawingGroup.ClipGeometry>
        <GeometryDrawing x:Name="path3767" Brush="#FF4D4D4D">
          <GeometryDrawing.Geometry>
            <PathGeometry FillRule="Nonzero" Figures="M36.512901,88.58266L36.512901,51.833165 8.88026306711254E-07,51.833165 8.88026306711254E-07,36.47519 36.512901,36.47519 36.512901,-1.76623310039759E-05 52.069777,-1.76623310039759E-05 52.069777,36.47519 88.582677,36.47519 88.582677,51.833165 52.069777,51.833165 52.069777,88.58266z" />
          </GeometryDrawing.Geometry>
        </GeometryDrawing>
      </DrawingGroup>
    </DrawingGroup>
</DrawingBrush.Drawing>

我的所有图标。但现在我想在Canvas.Background中显示我的DrawingBrush,它没关系:

  

<Grid Background="{DynamicResource Plus}" Height="200" Width="200" Margin="5">

但我想在Rectangle Geometry中保持图片比例库存,例如Rect =“0,0,88.582672,88.582672”。

我怎么能这样做?

Gat的

1 个答案:

答案 0 :(得分:0)

尝试将DrawingBrush的Stretch属性设置为uniform:

<DrawingBrush x:Key="Plus" Stretch="Uniform"> 
...