C# 使用XamlReader加载带有xml的xaml时出现奇怪的问题:space=";保留;

C# 使用XamlReader加载带有xml的xaml时出现奇怪的问题:space=";保留;,c#,silverlight,xaml,xamlreader,C#,Silverlight,Xaml,Xamlreader,当使用XamlReader从预定义的xaml文件加载我的应用程序的菜单时,我发现了一个非常奇怪的问题。 我需要定义xml:space=“preserve”的属性,xaml如下: 当我删除属性xml:space=“preserve”或将其更改为xml:space=“default”时,它将正常工作,并且我可以通过调用方法XamlReader.Load来获取MenuManager的对象。只加载一次。但是我确实需要在页面上保留空白,这里的代码看起来很奇怪。有人能解释一下吗? 谢谢 如果不想将xml:

当使用XamlReader从预定义的xaml文件加载我的应用程序的菜单时,我发现了一个非常奇怪的问题。 我需要定义
xml:space=“preserve”
的属性,xaml如下:

当我删除属性
xml:space=“preserve”
或将其更改为
xml:space=“default”
时,它将正常工作,并且我可以通过调用方法
XamlReader.Load来获取MenuManager的对象。只加载一次。但是我确实需要在页面上保留空白,这里的代码看起来很奇怪。有人能解释一下吗?

谢谢

如果不想将
xml:space=“preserve”
添加到所有元素,可以使用此附加参数来
XamlReader.Load

XamlReader.Load(xaml, new ParserContext() { XmlSpace = "preserve" });

还报告了一个可能在内部使用的bug,因此可以保留一个字。是的,我将sl版本从4升级到了5,问题得到了解决
        var uri = new Uri("/Sample;component/Assets/Menu.xaml", UriKind.Relative);
        var info = Application.GetResourceStream(uri);
        string xaml = null;
        using (StreamReader reader = new StreamReader(info.Stream))
        {
            xaml = reader.ReadToEnd();
        }
        //when the first time load, only a string value of
        //"Click the Button
(InvokeCommandAction)
View" is returned
        var temp1 = XamlReader.Load(xaml); 

        //when the second time load, all menu content loaded successfully and
        //converted to the object of MenuManager 
        readXaml = XamlReader.Load(xaml) as MenuManager;
XamlReader.Load(xaml, new ParserContext() { XmlSpace = "preserve" });