发生了XamlParseException
public MainPage()
{
InitializeComponent();
StringBuilder xaml = new StringBuilder();
xaml.Append("<TextBlock ");
xaml.Append("xmlns=\"http://schemas.microsoft.com/client/2007\" ");
xaml.Append("Canvas.Left=\"50\" Canvas.Top=\"30\" FontSize=\"50\" ");
xaml.Append("FontWeight=\"Bold\" Text=\"动态创建XAML对象\" ");
//创建TextBlock对象
TextBlock textblock =(TextBlock)XamlReader.Load(xaml.ToString());
parentCanvas.Children.Add(textblock);
xaml = new StringBuilder();
xaml.Append("<Line Stroke=\"Red\" ");
xaml.Append("xmlns=\"http://schemas.microsoft.com/client/2007\" ");
xaml.Append("X1=\"30\" Y1=\"30\" ");
xaml.Append("X2=\"200\" Y2=\"200\" StrokeThickness=\"3\" ");
Line line =(Line ) XamlReader.Load(xaml.ToString());
parentCanvas.Children.Add(line);
}
TextBlock textblock =(TextBlock)XamlReader.Load(xaml.ToString());
错误发生在这句
[解决办法]
xaml.Append("<TextBlock ");貌似没有在你的代码中看到结束符吧?还有就是xmlns=\"http://schemas.microsoft.com/....这里面的/会不会发生转义呢。。。。