我有这个带有自定义颜色属性的库。我希望能够像这样在 XAML 中使用这些属性:
<Style TargetType="{x:Type eg:MyWindow}">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="CustomClass.CustomColorProperty"/>
</Setter.Value>
</Setter>
</Style>
包含CustomClass的命名空间已被引用。我该怎么办?谢谢。
编辑:
我刚刚注意到CustomClass是静态的,所以我无法在 XAML 中创建它的实例。此外,当我输入eg:时,CustomClass不会出现在智能感知中。如果我有一个实例类,我无法让您的任何解决方案起作用,即使它们应该起作用。这种情况有解决方法吗?
编辑2:
这是实际的类和命名空间:
namespace Assergs.Windows
{
public static class OfficeColors
{
public class Background
{
public static Color OfficeColor1 = (Color)ColorConverter.ConvertFromString("#e4e6e8");
public static Color OfficeColor2 = (Color)ColorConverter.ConvertFromString("#dce0ed");
public static Color OfficeColor3 = (Color)ColorConverter.ConvertFromString("#a8c3e0");
}
}
}
这是 XAML 命名空间:
xmlns:aw="clr-namespace:Assergs.Windows;assembly=Assergs.Windows"
如果我按照 Zenuka 的建议使用这条线:
<SolidColorBrush Color="{x:Static aw:OfficeColors.Background.OfficeColor1}"/>
它在编译时抛出此错误:
Cannot find the type 'OfficeColors.Background'. Note that type names are case sensitive.