Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Read (and traverse) XAML file from MemoryStream

$
0
0

Hi,

I have an XAML document that I have to read from a MemoryStream (for the purpose of the example, I load a XAML file to a memorystream)
Here is a shortened version of the XAML file:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" >
    <Grid.Resources>
        <System:Decimal x:Key="example">-1</System:Decimal>
    </Grid.Resources>
</Grid>

I have to traverse the document and get the "-1" value from the <SystemDecimal> tag
How should I please do...Here is what I've achieved until now..without success:

StreamReader mysr = new StreamReader("example.xaml");
XmlDocument doc = new XmlDocument();
doc.Load(mysr);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("System", "clr-namespace:System;assembly=mscorlib");
XmlNode node = doc.SelectSingleNode("/Grid/Grid.Resources/System:Decimal", nsmgr);
Debug.Print(node.InnerText);

-Mrutyunjaya



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>