阅读XAML文件并创建元素

时间:2013-09-09 08:52:48

标签: c# wpf geometry

我有一个像这样的XAML文件:( Snippet)

<DrawingGroup x:Name="DrawingLayer">
<DrawingGroup.ClipGeometry>
  <RectangleGeometry Rect="0,0,540.866,507.982" />
</DrawingGroup.ClipGeometry>
<DrawingGroup>
  <DrawingGroup x:Name="shape1_1" Transform="1,0,0,1,20.0093,-394.221">
    <DrawingGroup x:Name="shadow1_2" Transform="1,0,0,1,0.3456,1.9728">
      <GeometryDrawing>
        <GeometryDrawing.Brush>
          <SolidColorBrush Color="#FF5B9BD5" Opacity="0.22" />
        </GeometryDrawing.Brush>
        <GeometryDrawing.Pen>
          <Pen Thickness="1" StartLineCap="Square" EndLineCap="Square" LineJoin="Miter">
            <Pen.Brush>
              <SolidColorBrush Color="#FF5B9BD5" Opacity="0.22" />
            </Pen.Brush>
          </Pen>
        </GeometryDrawing.Pen>
        <GeometryDrawing.Geometry>
          <RectangleGeometry RadiusX="0" RadiusY="0" Rect="0,394.596,113.386,113.386" />
        </GeometryDrawing.Geometry>
      </GeometryDrawing>
    </DrawingGroup>
    <GeometryDrawing Brush="#FF5B9BD5">
      <GeometryDrawing.Pen>
        <Pen Brush="#FFC8C8C8" Thickness="0.25" StartLineCap="Square" EndLineCap="Square" LineJoin="Miter" />
      </GeometryDrawing.Pen>
      <GeometryDrawing.Geometry>
        <RectangleGeometry RadiusX="0" RadiusY="0" Rect="0,394.596,113.386,113.386" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
  </DrawingGroup>

格式不正确。

我正在使用这样的XAML Reader:

StreamReader mysr = new StreamReader("C:\\Drawing Bath Convert\\Test with connectors.xaml");
DependencyObject rootObject = System.Windows.Markup.XamlReader.Load(mysr.BaseStream) as DependencyObject;   

返回带有子节点的对象,我可以为子节点等等,以便在运行时创建元素。

我想知道是否有人更有效地访问XAML DrawingGroup中的每个元素?

感谢;

0 个答案:

没有答案