Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Button icon gets mirrored, why?

This Button looks fine (see screenshot) when defining the image as done below. Note that the shield shaped icon with the letter 'T' is visualized correctly.

<Button Command="w:MainWindow.BrowseTorrentSite">
    <StackPanel>
        <Image Source="../icons/kickasstorrent.png" />
    </StackPanel>
</Button>

enter image description here

When I want to rely on the buttons enabled state, the icon gets mirrored.

<StackPanel 
      Orientation="Horizontal" 
      FlowDirection="RightToLeft">
        <Button 
            x:Name="KatButton" 
            Command="w:MainWindow.BrowseTorrentSite">
            <StackPanel>
                <Image>
                    <Image.Style>
                        <Style TargetType="Image">
                            <Style.Triggers>
                                <DataTrigger
                                    Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" 
                                    Value="True">

                                    <Setter Property="Source" Value="../icons/kickasstorrent.png" />
                                </DataTrigger>
                                <DataTrigger 
                                    Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" 
                                    Value="False">

                                    <Setter Property="Source" Value="../icons/kickasstorrent_disabled.png" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
            </StackPanel>
        </Button>
</StackPanel>

enter image description here

Note the shield shaped icon with the letter 'T' is now mirrored.

What is responsible for mirroring the icon?

If somebody has tips to debug this in whatever way possible, feel free to point me in the right direction!

like image 356
bas Avatar asked Dec 26 '22 15:12

bas


1 Answers

The problem is in the parent StackPanel. If the StackPanel is defining the FlowDirection from right to left, the Image definition inherits this property which results in the flipped icon.

To solve this problem redefine left to right on the image itself.

    <StackPanel 
        Orientation="Horizontal" 
        FlowDirection="RightToLeft">
        <Button>
            <Image FlowDirection="LeftToRight">
                <Image.Style>
                    <!-- etc etc -->
                </Image.Style>
            </Image>
       </Button>
    </StackPanel>
like image 95
bas Avatar answered Jan 15 '23 05:01

bas