1
A
回答
1
XAML是XML,因此可以解析为XML并使用任何这些方法来提取所需的数据。
0
您需要对图像文件信息的格式进行一些更具体的描述,但如果它只是作为文件路径存储在XAML中,则使用.NET的XMLTextReader应该可以做到。 c-sharpcorner.com有一些很好的代码样本可以帮助你。
2
如果你有一个XML文件(或字符串)是这样的:
<ImageData>
<Path>Res\image.xaml</Path>
</ImageData>
...和XAML的字典文件中的 “RES \ image.xaml” 是这样的:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Image x:Key="imageKey" Source="img.jpg"/>
</ResourceDictionary>
...你可以(使用LINQ to XML)得到这样的图像元素的源路径:
private string GetImagePath(string xmlString)
{
XElement xmlData = XElement.Parse(xmlString);
XElement pathElement = xmlData.XPathSelectElement("ImageData/Path");
if (pathElement == null) return null;
string xamlPath = pathElement.Value;
XElement xamlData = XElement.Load(xamlPath);
XElement imageElement = xamlData.XPathSelectElement("//Image");
if (imageElement == null) return null;
XAttribute pathAttribute = imageElement.Attribute("Source");
return pathAttribute == null ? null : pathAttribute.Value;
}
这是当然的,粗略的指南如何做到这一点,当然你可以在做一些实验之后调整它,以适应你的模型。
感谢您的示例代码.. 但我的要求是与网络2.0。 你有什么想法,我怎么做dotnet 2.0相同? – 2009-07-28 05:27:32