How to reference a property from a static member in XAML?

Suppose I have two classes:

public class LocalResources { public Color ForegroundColor { get; set; } } public static class OrganisationModule { public static LocalResources Resources = new LocalResources { ForegroundColor = Color.FromRgb(32, 32, 32) }; } 

In XAML code, why can't I do this (assuming all xml namespaces exist)?

 <TextBlock Foreground="{x:Static Modules:OrganisationModule.Resources.ForegroundColor}" /> 

When compiling, I get an error: Cannot find the type 'OrganisationModule.ColorManager'. Note that type names are case sensitive. Cannot find the type 'OrganisationModule.ColorManager'. Note that type names are case sensitive.

+4
source share
1 answer

There are two errors here. First, in the OrganizationModule class, you need to provide resources as a property. This is currently not a property, you need to write Get and / or Set

Then for linking we need the expression

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

Source: https://habr.com/ru/post/1338027/


All Articles