Hi,
I'm experimenting with changing colors in the new Office 2013 theme in version 14.1. I'm using the Infragistics Color Tuner from within Visual Studio.
For most controls, everything works as expected, but the Ribbon does not seem to act upon changes to the colors. The attached zip file shows two examples of the Ribbon being 'washed' with a green color.
As the ribbon1.jpg image shows, the Ribbon still uses the default blue base color.
The ribbon2.jpg shows another strage effect in that parts of the ComboEditorTool uses the default, blue color while other parts (the expanded part) uses the green color I supplied.
In addition to making modifications to my existing application I also tried this on a simple sample application, but with the same effect; The ribbon is not correctly 'washed' with the changed colors. Are the changes made by the Infragistics Color Tuner not sufficient for modifying the Ribbon, and are additional steps required ? What am I doing wrong ?
Regards,Leif
Hi Leif,
I contacted our developers for their explanation and recommendation. What you are trying doesn’t work for a few reasons.
An exception happens because you cannot change a Style that has been sealed. You’ll notice that even if you don’t set the Theme and don’t have any resources in the App.Resources for the ribbon the Style you get from the FindResource is sealed. That Style would be the default style for the control and the framework seals that because it is shared across all instances of the control which may be on different threads.
As for having resources for the XamRibbon in the App.Resources, it seems there is a bug in the WPF framework because the FindResource seems to still return the default style. Calling the FindResource a second time seems to get the resource from the App.Resources. However, the framework still freezes resources added to the App.Resources so an exception would still be thrown.
The suggest for you is to register a static event handler for the Opened event of the RibbonContextMenu ( since it is a RoutedEvent ) and handle the event that way.
public partial class MainWindow : Window
{
static MainWindow()
EventManager.RegisterClassHandler(typeof(RibbonContextMenu), RibbonContextMenu.OpenedEvent,
new RoutedEventHandler((o, e) =>
var cm = o as RibbonContextMenu;
var ribbon = XamRibbon.GetRibbon(cm);
var window = ribbon != null ? Window.GetWindow(ribbon) : null;
if (window is MainWindow)
((MainWindow)window).ContextMenuOpened(o, e);
}));
}
Registering the event this way allows you to add the Theme and the Wash as I originally suggested in the App.xaml. And you can dispense with your logic in the Loaded event.
Let me know if you have any questions.
I guess I can live with this solution.
As for having resources for the XamRibbon in the App.Resources, it seems there is a bug in the WPF framework because the FindResource seems to return the default style. Calling the FindResource a second time seems to get the resource from the App.Resources. However, the framework still freezes resources added to the App.Resources so an exception would still be thrown.
this workaround works fine in my main application as well. However, it would be nice to know if this is a bug, especially since any further use of the Infragistics Color Tuner will put the corresponding code back into App.xaml.
I have found that if you add the MergedDictionaries, the Theme and the ResourceWasher, directly to the XamRibbon instead of in the app.xaml that solves the issue you were having.
<igRibbon:XamRibbon.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<igThemes:RibbonOffice2013 />
<igThemes:ResourceWasher AutoWash="True" WashColor="#FF76923C" WashMode="HueSaturationReplacement" >
<igThemes:ResourceWasher.SourceDictionary>
<igThemes:RibbonWashBaseLight />
</igThemes:ResourceWasher.SourceDictionary>
</igThemes:ResourceWasher>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</igRibbon:XamRibbon.Resources>
I'm looking into the explanation for this behavior.