How to style RibbonComboBox

这一生的挚爱 提交于 2020-01-25 23:12:08

问题


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:

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

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

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?

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15615502/how-to-style-ribboncombobox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!