Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
IgRibbon Toggle Button background style on IsChecked
posted

I want to keep Background of toggle button transparent on  style trigger "Is checked = true".

I Want the button to stay flat even after the button is checked.

Parents Reply
  • 2680
    Verified Answer
    Offline posted in reply to Anushri Jain
    Hello Anushri,

     

    Thank you for clarifying the control in question.

     

    When it comes to styling the XamRibbon’s tools, it does not suffice to simply set the Background property. In this forum thread, you could refer to Andrew Smith’s answer as to why this is so. To paraphrase, the button tools original templates are quite complicated, and their borders and backgrounds are rendered by the RibbonButtonChrome class. This class uses different brushes for different states, which also depend on the theme being used. 

    As you can see, the suggestion for modifying the background is to either retemplate the tool or add the mentioned brushes with the required colors. However, when it comes to the ToggleButton, after referencing the default styles, I determined that retemplating a button tool would not be a trivial task and the ToggleButton uses some different brushes, shared between controls.

     

    So, if you want to have full control over a particular toggle button style, my suggestion is to simply include your own button into a RibbonGroup, for instance. As you may know, you can use other controls, apart from the special ribbon tools in the RibbonGroups as well. WPF does provide a native ToggleButton.

     

    Additionally, below I am attaching a small sample with a XamRibbon where such a custom toggle button is included. Of course, you could define the template and all properties differently, depending on your requirements:

     

    <ToggleButton Content="WPF ToggleButton" Height="20" >
                                        <ToggleButton.Style>
                                            <Style TargetType="{x:Type ToggleButton}">
                                            <Setter Property="BorderBrush"
                                                    Value="Transparent" />
                                            <Setter Property="Foreground"
                                                    Value="#B00020" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                        <StackPanel Orientation="Horizontal"
                                                                    VerticalAlignment="Center"
                                                                    Background="Transparent" Height="20" >
                                                            <Image Source="rocket.png"
                                                                   Width="16"
                                                                   Height="16"
                                                                   VerticalAlignment="Center" />
                                                            <TextBlock Text="WPF ToggleButton"
                                                                       Width="100"></TextBlock>
                                                        </StackPanel>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                            <Style.Triggers>
                                                <Trigger Property="IsChecked"
                                                         Value="True">
                                                    <Setter Property="Foreground"
                                                            Value="OrangeRed" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                        </ToggleButton.Style>
                                    </ToggleButton>

    Apart from that, directly styling a button tool is considered to be a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at <https://es.infragistics.com/community/ideas>.

     

    Let me know if you have any questions.

     

    Sincerely,
    Bozhidara Pachilova
    Associate Software Developer
Children