I am looking to use an IValueConverter with a value that I am getting from the resources of an application. I noticed that a similar question was asked a few years ago here: How to bind to a StaticResource with a Converter?.
However, updating the Source attribute to an object in the resources didn't work for me. My particular case:
<TextBlock Text="SampleText" Foreground="{Binding Source={StaticResource AppThemeColor}, Converter={StaticResource ThemeColorToBrushConverter}, ConverterParameter={StaticResource ApplicationForegroundThemeBrush}, Mode=OneWay}" />
The AppThemeColor is defined and set dynamically in the code behind at an early stage of the app launch. The logic in the converter simply says to use the color provided unless the app is in highcontrast mode, in which case it uses the brush supplied in the ConverterParameter.
Does anyone know of any pitfalls I might be running into here? There are no compile or run time errors. The text just doesn't appear and the converter's convert doesn't seem to be getting called.
EDIT: Some were asking how I was setting the AppThemeColor dynamically. I simply added the following one-liner here in the App.xaml.cs's OnActivatedAsync:
Application.Current.Resources[AppThemeColorResourceKey] = (themeExists) ? branding.ThemeColor : blueThemeColor;