
Hello there,
is it possible to set the background of the ribbon in code or in xaml without changing the themes?
Thanks in Advance.
Best regards,
Patrick
Hello there,
is it possible to set the background of the ribbon in code or in xaml without changing the themes?
Thanks in Advance.
Best regards,
Patrick
Hi Patrick,
In the legacy Ribbon product's ribbon, the Ribbon.Background property controls the area behind the tab headers. The resource brush that controls the backgorund in the tab area doesn't have a Ribbon property, but can be overridden in App.Resources like this:
<SolidColorBrush x:Key="{x:Static themes:AssetResourceKeys.LegacyRibbonTabControlBackgroundNormalBrushKey}" Color="Red" />
Whereas in the newer Bars product's ribbon, the Ribbon.Background property controls the tab area background.
Hi there,
is there a simple way to get the following to update the ribbon background on a theme change?
I tried to invalidate the ribbon but this didn´t help.
<SolidColorBrush
x:Key="{x:Static themes:AssetResourceKeys.LegacyRibbonTabControlBackgroundNormalBrushKey}"
presentationOption:Freeze="True"
Color="{Binding Converter={phx:SolidColorBrushToColorConverter}, ConverterParameter={x:Static themes:AssetResourceKeys.ContainerBackgroundLowestBrushKey}}" />
Hi Patrick,
Keep in mind that if you freeze a brush, it won't update beyond the first time its Color is set. That could be the problem here.
If it still doesn't update after unfreezing, you might have to programmatically remove the brush from your App.Resources and then add a new one in its place with the same key. That should work and is effectively what we do in our theme changes.
Hi there,
i tried unfreezing it but this didn´t help.
I also tried to remove the brush from the resources using the following code but this didn´t help either.
Is there something I´m doing wrong?
Thanks in Advance.
foreach (var dictionary in Application.Current.Resources.MergedDictionaries)
{
foreach (var key in dictionary.Keys)
{
if (key is ComponentResourceKey componentResourceKey && componentResourceKey.ResourceId.ToString() == "LegacyRibbonTabControlBackgroundNormalBrushKey")
{
sharedResource = dictionary;
keyToDelete = componentResourceKey;
break;
}
}
}
sharedResource.Remove(keyToDelete);
sharedResource.Add(keyToDelete, new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 0)));
[Modified 5 months ago]
Hi Patrick,
I did this test in our sample app and it worked fine to show the ribbon background in yellow right after the code executed:
Application.Current.Resources.Remove(AssetResourceKeys.LegacyRibbonTabControlBackgroundNormalBrushKey);
Application.Current.Resources.Add(AssetResourceKeys.LegacyRibbonTabControlBackgroundNormalBrushKey,
new SolidColorBrush(Color.FromRgb(255, 255, 0)));
Thanks a lot. This worked.
Please log in to a validated account to post comments.