Background of Ribbon

Ribbon for WPF Forum

Posted 5 months ago by Patrick Neubauer
Version: 24.1.3
Avatar

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  

Comments (6)

Answer - Posted 5 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.


Actipro Software Support

Posted 5 months ago by Patrick Neubauer
Avatar

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}}" />

Posted 5 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.


Actipro Software Support

Posted 5 months ago by Patrick Neubauer
Avatar

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]

Answer - Posted 5 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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)));


Actipro Software Support

Posted 5 months ago by Patrick Neubauer
Avatar

Thanks a lot. This worked. 

The latest build of this product (v24.1.5) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.