C# 如何从XAML中的静态成员引用属性?

C# 如何从XAML中的静态成员引用属性?,c#,wpf,xaml,static,C#,Wpf,Xaml,Static,假设我有两个这样的课程: public class LocalResources { public Color ForegroundColor { get; set; } } public static class OrganisationModule { public static LocalResources Resources = new LocalResources { ForegroundColor = Color.FromRgb(32,

假设我有两个这样的课程:

public class LocalResources
{
    public Color ForegroundColor { get; set; }
}

public static class OrganisationModule
{
    public static LocalResources Resources = new LocalResources 
    { 
        ForegroundColor = Color.FromRgb(32, 32, 32)
    };
}
在XAML代码中,为什么我不能这样做(假设存在所有正确的xml名称空间)



编译时,出现错误:
找不到类型“OrganizationModule.ColorManager”。请注意,类型名称区分大小写。

这里有两个错误。首先,在OrganizationModule类中,您需要提供资源作为属性。当前它不是一个属性,您需要编写Get和/或Set

那么对于绑定,我们需要下面的表达式

Foreground="{Binding Path=ForegroundColor,Source={x:Static Modules:OrganisationModule.Resources}}" /> 

啊,当然!实际上,我不需要将资源设置为属性,因为它是静态的,但除此之外,这绝对是我需要的答案。谢谢
Foreground="{Binding Path=ForegroundColor,Source={x:Static Modules:OrganisationModule.Resources}}" />