Search code examples
wpfxamlribbon

Adding Unselectable controls to RibbonMenuButton


I am working on a WPF project and I started developing the Ribbon area. I just put a RibbonMenuButton and added three RibbonTextBox inside of it. I want these TextBoxes to retrieve some data from the user. Everything is fine so far.

<rb:RibbonMenuButton LargeImageSource="/image.png" Label="Settings"   >

    <rb:RibbonTextBox Label="Field 01:" Text="{Binding Field01 }" />
    <rb:RibbonTextBox Label="Field 02:" Text="{Binding Field02 }" />
    <rb:RibbonTextBox Label="Field 03:" Text="{Binding Field03 }" />

</rb:RibbonMenuButton>

My problem is that the RibbonTextBox becomes a menu item, i.e. I can click it and select it.

But I want to avoid this behavior, I just want to have an "unselectable" RibbonTextBox.

Is there a way to achieve that?

Thank you in advance.


Solution

  • I found the solution here:

    <Style TargetType="{x:Type rb:RibbonMenuItem}">
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type rb:RibbonMenuItem}">
                     <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" 
                         Content="{TemplateBinding Header}" Grid.Column="1" 
                         ContentStringFormat="{TemplateBinding HeaderStringFormat}" 
                         ContentSource="Header" 
                         Margin="{TemplateBinding Padding}" 
                         RecognizesAccessKey="True" 
                         VerticalAlignment="Center"/>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>
    

    This works pretty well for me.