I've got a xaml with a german umlaut (s. below) now when I try to parse it, I get an invalidchar error.
When I don't use an XamlParser Context it works. But I have to use it in order to set some type mappings
XAML:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:test="clr-namespace:BR.UI.Tests.Items;assembly=BR.UI.ViewLocator.Tests"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<test:SampleViewModel />
</UserControl.DataContext>
<Grid>
<Label>ö</Label>
</Grid>
</UserControl>
Code which parses it
var context = new ParserContext();
var result = System.Windows.Markup.XamlReader.Parse(xaml,context);
I can't find anything to set an encoding hint (which would be .net String UTF-16) what am I doing wrong?
I also tried to inject the encoding with an XmlParserContext.
var xmlcontext = new XmlParserContext(null, null, null, XmlSpace.Preserve,
Encoding.Unicode);
var context = new ParserContext(xmlcontext);
But it didn't help :-(
What do I need to do? Is there some kind of XAML encoding?
Answering my own question hope that is ok.
What helped for me was using the
System.Windows.Markup.XamlReader.Load(stream,XamlParserContext)
Method.
s. http://msdn.microsoft.com/de-de/library/ms590388.aspx
This method seems to respect the encoding of the string variable.
I still don't understand why this doesn't work with the Static ParseMethod. But I hope this solution will help someone else to safe time :-)