WPF Button icon gets mirrored, why?

二次信任 提交于 2019-12-10 16:53:46

问题


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>

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>

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!


回答1:


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>


来源:https://stackoverflow.com/questions/20911471/wpf-button-icon-gets-mirrored-why

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!