简体   繁体   中英

C# WPF RibbonButton Change Icon on MouseOver

i have a Ribbonbutton wich i want to change the Icon on MouseOver but it does not seem to work.

Here is my Code:

<RibbonButton Label="Verbindung testen" LargeImageSource="../Resources/Buttons/disconnect.png" Command="{Binding SettingsVM.TestConnectionCommand}">
                    <RibbonButton.Style>
                        <Style TargetType="{x:Type RibbonButton}">
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="LargeImageSource" Value="../Resources/Buttons/connect.png"/>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="False">
                                    <Setter Property="LargeImageSource" Value="../Resources/Buttons/disconnect.png"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </RibbonButton.Style>
</RibbonButton>

It just shows the first Icon "disconnect.png" and on mouse over it gets highlighted like all the other buttons, but no image change.

I also tried it this way, with ControlTemplate:

<RibbonButton Label="Verbindung testen" LargeImageSource="../Resources/Buttons/disconnect.png" Command="{Binding SettingsVM.TestConnectionCommand}">
<RibbonButton.Template>
    <ControlTemplate TargetType="{x:Type RibbonButton}">
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="LargeImageSource" Value="../Resources/Buttons/connect.png"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="False">
                <Setter Property="LargeImageSource" Value="../Resources/Buttons/disconnect.png"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</RibbonButton.Template>

Here it doesnt show an icon at all.

Found the Answer!

WPF RibbonButton: LargeImageSource and Label not updated via DataTriggers

The problem is your setting properties for LargeImageSource and Label in the button itself. When you do this it takes precidence over your style triggers. I suggest using setters in the style to set your defaults, and remove the property settings it the button.

So it has to be:

<RibbonButton Label="Verbindung testen" Command="{Binding SettingsVM.TestConnectionCommand}">
<RibbonButton.Style>
    <Style TargetType="{x:Type RibbonButton}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="LargeImageSource" Value="../Resources/Buttons/connect.png"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="False">
                <Setter Property="LargeImageSource" Value="../Resources/Buttons/disconnect.png"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</RibbonButton.Style>

Removing the "LargeImageSource" from the Button itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM