Lets say I have a two classes like this:
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 the right xml namespaces exist)?
<TextBlock Foreground="{x:Static Modules:OrganisationModule.Resources.ForegroundColor}" />
When I compile, I get the error: Cannot find the type 'OrganisationModule.ColorManager'. Note that type names are case sensitive.
There are two mistakes here. First in the OrganisationModule class you need to provide Resources as property. Currently it is not a property, you need to write Get and/or Set
Then for Binding we need below expression
Foreground="{Binding Path=ForegroundColor,Source={x:Static Modules:OrganisationModule.Resources}}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With