如何在xml文件中定义XAML的结构? [英] How to define the structure of a XAML in an xml file?
问题描述
我可以在WPF中执行此操作
I can do this in WPF
string xaml = "<grid margin="0" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><textblock text="Page one" fontsize="32" foreground="White" horizontalalignment="Center" verticalalignment="Center" /> </grid>";
StringReader stringReader = new StringReader(xaml);
XmlReader xmlReader = XmlReader.Create(stringReader);
UIElement MyVisualTree = (UIElement)XamlReader.Load(xmlReader);
Layout.Children.Add(MyVisualTree);
我想在XML文件中定义string xaml = ...的结构,如下所示:
I want to define the structure of the "string xaml = ..." in an XML file as follows:
<menuitem tipo="C" xaml=" <Grid> ... </Grid>" estado="E" />
但尝试处理时告诉我有错误
<网格
有没有办法告诉xml尝试ContenidoGrid =..中的所有内容,将其视为简单文本而不是以特殊字符(<,>)发布。
but trying to process tells me that there is an error in
"<" Grid
Is there any way to tell xml try everything in ContenidoGrid = ".." , treat it as a simple text and not be posting in special characters (< , >).
推荐答案
代码示例的最后一行是而不是XML 。它的格式不正确且无法解析。
在使用XAML和其他XML应用程序之前,您需要学习XML本身。您的语法问题非常基本:您无法在开始标记中添加任何标记。您只在开始和结束标记之间插入内部XML:
The last line of your code sample is not XML at all. It is not well-formed and cannot be parsed.
Before working with XAML and other XML applications, you need to learn XML itself. Your problem with the syntax is very basic: you cannot add any tags in the opening tags. You only insert inner XML between opening and closing tags:
<someElement someAttribute="you cannot have XML inside the tag">
<!-- any inner XML, should also be well-formed -->
</someElement>
请参阅:
http://en.wikipedia.org/wiki/XML [ ^ ],
http:// www .w3.or g / TR / xml / [ ^ ],
http://www.xml.com/axml/testaxml.htm [ ^ ]。
Please see:
http://en.wikipedia.org/wiki/XML[^],
http://www.w3.org/TR/xml/[^],
http://www.xml.com/axml/testaxml.htm[^].
这篇关于如何在xml文件中定义XAML的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!