1

我无法使用 Markup.XamlReader.Load 方法打开具有自定义命名空间的 .xaml 文件。我喜欢这样:

stream = openFileDialog1.OpenFile();
System.Windows.Markup.ParserContext parserContext = new System.Windows.Markup.ParserContext();
parserContext.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
parserContext.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
parserContext.XmlnsDictionary.Add("ex", "clr-namespace=Extensions;assembly=Extensions");

viewport = System.Windows.Markup.XamlReader.Load(stream, parserContext) as Viewport3D;  

我在程序集中有以下 DependencyProperty;

namespace Extensions
{
    public class Ext
    {
        public static DependencyProperty NameProperty = DependencyProperty.RegisterAttached("Name", typeof(string), typeof(Ext));

        public static string GetName(DependencyObject target)
        {
            return (string)target.GetValue(NameProperty);
        }

        public static void SetName(DependencyObject target, string name)
        {
            target.SetValue(NameProperty, name);
        }
    }
}

我的问题是我在 XamlReader.Load 方法中得到一个 XamlParseException,告诉我这个:无法设置未知成员 {clr-namespace=Extensions;assembly=Extensions}Name。

.xaml 文件中的“未知成员”设置为 ModelVisual3D 对象,如下所示:

我能找到的关于这个错误的所有信息都建议我做我已经尝试过的事情。请帮我!

4

1 回答 1

0

您需要在 XAML 中为附加属性指定类名和属性名。例如

<TextBox ex:Ext.Name="MyName"/>
于 2022-01-24T01:01:06.913 回答