How to style RibbonComboBox

2019-09-15 19:53发布

I have described my problems with binding the SelectedItem of the RibbonComboBox. Another very ugly issue arises when trying to style this control.

Starting with the unstyled ComboBox from the post mentioned above:

<r:RibbonComboBox >
    <r:RibbonGallery SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
        <r:RibbonGalleryCategory ItemsSource="{Binding Controls}" DisplayMemberPath="Caption" />
    </r:RibbonGallery>
</r:RibbonComboBox>

I get the expected result:

enter image description here

But when applying a style with the help of Microsoft Blend (Preview for VS 2012), Object | Edit Style | Edit a Copy... (copying only the Template, with Blend or Visual Studio, has the same effect):

enter image description here

The selected item will no longer be displayed correctly - instead of the DisplayMemberPath property, the type name is shown. Items in the dropdown are still correct. Note that I did not yet change the style in any way, it is the default style/template that gets extracted that will produce this issue.

<r:RibbonComboBox Style="{DynamicResource RibbonComboBoxStyle1}" >

enter image description here

I also had trouble to style my dropdown items (mainly wanted to change the mouseover background cornerradius), because the ItemContainerStyle for the RibbonComboBox will have target type RibbonMenuItem and does not seem to have an effect on the actual RibbonGalleryItems.

  1. How to fix the RibbonComboBox style?
  2. How can I get to the RibbonGalleryItem style by way of Blend/VS?

2条回答
贼婆χ
2楼-- · 2019-09-15 20:08

You may want to take a look at JetBrains dotPeek decompiler.

One of its features is:

"... decompile .baml files, enabling you to reconstruct XAML UI definitions."

In addition, I just finished to edit visual RibbonCombobox and its relative controls by using the decompiler mentioned above, which decompiled the entire Ribbon library including original Microsoft .XAML themes.

查看更多
姐就是有狂的资本
3楼-- · 2019-09-15 20:11

Currently, I have solved this issue by extracting the default RibbonComboBox style directly from RibbonControlsLibrary.dll (Resources/RibbonControlsLibrary.g.resources/themes/generic.baml) with ILSpy.

This is tedious work, because the style references other StaticResources in the same file, so you need to find and extract those, too.

The same applies to the RibbonGalleryItem style, it can be extracted like this, but I would prefer a "cleaner" solution involving Blend or Visual Studio.

查看更多
登录 后发表回答