Issues with XamlWriter

42 views Asked by At

I've some issues with XamlWriter. I've a button with a TextOptions:

<Button FontFamily="Calibri" FontSize="67" FontWeight="SemiBold" Tag="K -" Margin="1,1,1,1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextOptions.TextHintingMode="Animated" Grid.Column="4" Grid.Row="1">

try getting xaml with:

string xaml = XamlWriter.Save(ctl);

XamlWriter adds this line:

xmlns:msim="clr-namespace:MS.Internal.Media;assembly=PresentationCore"

and change TextOptions to TextOptionsInternal

msim:TextOptionsInternal.TextHintingMode="Animated"

When I try to load xaml with:

ParserContext parser = new ParserContext();
parser.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
parser.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");               
parser.XmlnsDictionary.Add("s", "clr-namespace:System;assembly=mscorlib");
parser.XmlnsDictionary.Add("msim", "clr-namespace:MS.Internal.Media;assembly=PresentationCore");

UIElement el = System.Windows.Markup.XamlReader.Parse(xaml, parser) as UIElement;

I get the following error:

'Impossibile impostare il membro sconosciuto '{clr-namespace:MS.Internal.Media;assembly=PresentationCore}TextOptionsInternal.TextHintingMode'

I've tried everything but I can't solve it, any tips?

Thanks in advance, Stefano.

The only way to make it work that I've found is to use String.Replace to replace TextOptionsInternal with TextOptions and manually remove MS.Internal.Media reference

0

There are 0 answers