从字符串创建动态画布

时间:2016-06-13 12:23:28

标签: c# wpf xaml

我想从反序列化中创建图形元素。我可以用XML序列化我的画布及其子元素,并以字符串形式检索它。内容在字符串中看起来像这样(Xaml序列化):

<Canvas
  Background="#00FFFFFF"
  Name="overlay"
  Width="1042"
  Height="669"
  Panel.ZIndex="2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <Path
    Stroke="#FFFF0000"
    StrokeThickness="4">
    <Path.Data>
      <LineGeometry
        StartPoint="348,190"
        EndPoint="407,321" />
    </Path.Data>
  </Path>
  <Path
    Stroke="#FFFF0000"
    StrokeThickness="4">
    <Path.Data>
      <LineGeometry
        StartPoint="567,132"
        EndPoint="586,284" />
    </Path.Data>
  </Path>
  <Path
    Stroke="#FFFF0000"
    StrokeThickness="4">
    <Path.Data>
      <LineGeometry
        StartPoint="299,425"
        EndPoint="553,390" />
    </Path.Data>
  </Path>
  <Path
    Stroke="#FFFF0000"
    StrokeThickness="4">
    <Path.Data>
      <LineGeometry
        StartPoint="653,315"
        EndPoint="539,424" />
    </Path.Data>
  </Path>
  <Path
    Stroke="#FFFF0000"
    StrokeThickness="4">
    <Path.Data>
      <LineGeometry
        StartPoint="432,464"
        EndPoint="685,439" />
    </Path.Data>
  </Path>
</Canvas>

当我点击按钮例如,我如何将此画布放在屏幕上?如何从字符串动态创建UI元素?

0 个答案:

没有答案