I'm using my custom converter in my control's background.
<Border Background="{Binding IsSelected, Converter={StaticResource SelectedToProfileBorderBackgroundConverter}}" CornerRadius="8" Width="214" Height="112">
My converter will return a brush from the resourcedictionary that I declared.
public class SelectedToProfileBorderBackgroundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool status = (bool)value;
if (status)
{
return Application.Current.Resources["ProfileBorderSelectedBackground"];
}
else
{
return Application.Current.Resources["ProfileBorderBackground"];
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
<SolidColorBrush x:Key="ProfileBorderBackground" Color="#EEEEEF"/>
<SolidColorBrush x:Key="ProfileBorderSelectedBackground" Color="#EEEEEF"/>
The problem is Application.Current.Resources["ProfileBorderSelectedBackground"]
return a staticResource instead of DynamicResource.
So if I change the value of ProfileBorderSelectedBackground
through a change in theme that user selected, the border background is not changed.
Is there a way to let Application.Current.Resources["ProfileBorderSelectedBackground"]
return a DynamicResource instead of StaticResource?
Read more here: https://stackoverflow.com/questions/66997224/return-dynamicresource-in-ivalueconverter
Content Attribution
This content was originally published by Coel at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.