Subclassing Ribbon controls

Jul 19, 2010 at 12:54 PM

Hi,

I needed to create a class deriving from the RibbonGroupBox. However, when I try to add an instance of such class to the RibbonTabItem the group box does not show up, no matter if it has been added in XAML or in code behind. The same issue applies to the subclass of the Button control.

I removed all the code from the subclass including the DeaultStyleKey override. Now it just contains of the class declaration. Nothing helped.

I will be greateful for any advice in this matter.

Regards,

David

Coordinator
Jul 19, 2010 at 1:20 PM

I think the default style of RibbonGroupBox is not applied. This is a issue of WPF. To avoid that you need to set the style manually or add this line where your styles are:

<Style x:Key="{x:Type MyRibbonGroupBox}" TargetType="{x:Type MyRibbonGroupBox}" BasedOn="{StaticResource RibbonGroupBoxStyle}"/>

Hope it helps...
Daniel

Jul 19, 2010 at 2:11 PM

Thanks for quick reply.

Your solution is sufficient as long as I explicitly specify the style on each instance of my control or at the root of the visual tree. However I would like to use the DefaultStyleKey + Themes method and separate the structure of my menu from its actual representation. It works fine with the standard WPF controls and I can't find the reason why it does not with the RibbonGroupBox. If I remove the x:Key part the style does not get applied.

I successfully used this method with the RibbonTabItem control. After some time I figured out that I should base my style on the {StaticResource RibbonTabItemStyle} not the {StaticResource {x:Type RibbonTabItem}}, which is a common practice. Nevertheless I managed to get it working. I followed the same steps with the RibbonGroupBox but it failed.

So, still struggling.

Coordinator
Jul 19, 2010 at 3:41 PM

It works fine ONLY with the standard WPF controls. It doesn't work with custom controls, try it. We add workaround for RibbonTabItem only. We are still searching the good way...

Jul 19, 2010 at 4:25 PM

That is strange. I have created a number of custom controls. For each of them I specified the DefaultStykeKey and created styles for different themes. After that I was able to subclass those controls and provide new theme styles basing on the default ones.

Could you please direct me to the workaround made for RibbonTabItem, maybe I just change the code myslef while waiting for this problem to be solved in future versions.

Kind regards

Coordinator
Jul 19, 2010 at 4:55 PM
As for workaround, we just coerce style. To avoid misunderstanding, please, create a new issue in the issue tracker, provide code snippets and expected result. Daniel
Jul 19, 2010 at 6:23 PM

Done, I've created an issue. Hope it can be fixed.

Regards, David.