C# 如何让XAML编译器在自定义类上使用文本内容属性?
给出一个简单的C#类定义,如:C# 如何让XAML编译器在自定义类上使用文本内容属性?,c#,xaml,C#,Xaml,给出一个简单的C#类定义,如: [System.Windows.Markup.ContentProperty("PropertyOne")] public class SimpleBase { public string PropertyOne { get; set; } public string PropertyTwo { get; set; } } 为什么不能在下面的xaml中省略单词Test周围的sys:string标记
[System.Windows.Markup.ContentProperty("PropertyOne")]
public class SimpleBase
{
public string PropertyOne { get; set; }
public string PropertyTwo { get; set; }
}
为什么不能在下面的xaml中省略单词Test周围的sys:string标记
<custom:SimpleBase x:Class="TestType"
xmlns:custom="clr-namespace:ConsoleApplication1;assembly="
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<sys:String>Test</sys:String>
</custom:SimpleBase>
试验
不知何故,编译器正确地将文本转换为字符串类型,为什么它不适用于我的自定义类型
上下文可以在我的博客上找到:因此,经过大量挖掘,我发现了这个问题。为了能够支持自定义内容,基类必须在不同的程序集中声明 谈论晦涩。尽管如此,还是将SimpleBase的定义移动到一个新程序集,并更新xmlns的定义:custom to match和Bingo,仅使用直接字符串内容不会再出现错误
谢谢你的阅读。所以,经过大量挖掘,我发现了这个问题。为了能够支持自定义内容,基类必须在不同的程序集中声明 谈论晦涩。尽管如此,还是将SimpleBase的定义移动到一个新程序集,并更新xmlns的定义:custom to match和Bingo,仅使用直接字符串内容不会再出现错误 谢谢你的阅读