Search code examples
wpfribbon

How to Style RibbonSplitButton ItemTemplate


I have a RibbonSpitButton with an ItemSource and an ItemTemplate defined in this way:

<RibbonSplitButton x:Name="SplitButton3DViews" 
                                   ItemsSource="{Binding items}"
                                   Label="{String Views3D}"
                                   IsCheckable="False">
    <RibbonSplitButton.ItemTemplate>
        <DataTemplate>
            <RibbonMenuItem Header="{Binding Name}" ImageSource="{Binding Icon}" Command="{Binding cmd}"/>
        </DataTemplate>
    </RibbonSplitButton.ItemTemplate>
</RibbonSplitButton>

Everithing works but the graphical results is this: enter image description here

How can I put icons of sub-items in the proper place (in the blue part of the menu)?


Solution

  • You can create style for RibbonMenuItem in resources of RibbonSplitButton and set there appropriate properties.

    <ribbon:RibbonSplitButton x:Name="SplitButton3DViews" 
                   ItemsSource="{Binding items}"
                   Label="Views3D"
                   IsCheckable="False" >
        <ribbon:RibbonSplitButton.Resources>
            <Style TargetType="{x:Type ribbon:RibbonMenuItem}">
                <Setter Property="Header" Value="{Binding Path=Name}" />
                <Setter Property="Command" Value="{Binding Path=cmd}" />
                <Setter Property="ImageSource" Value="{Binding Icon}" />
            </Style>
        </ribbon:RibbonSplitButton.Resources>                        
    </ribbon:RibbonSplitButton>
    

    Result:

    enter image description here