WPF 按钮图标被镜像,为什么?

标签 wpf xaml button icons

如下所示定义图像时,此按钮看起来不错(请参见屏幕截图)。请注意,带有字母“T”的盾形图标正确显示。

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

enter image description here

当我想依赖按钮启用状态时,图标会被镜像。
<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

请注意,带有字母“T”的盾形图标现在已镜像。

什么负责镜像图标?

如果有人有以任何可能的方式调试它的技巧,请随时为我指出正确的方向!

最佳答案

问题出在父 StackPanel 中。如果StackPanel正在定义 FlowDirection从右到左,Image定义继承了导致翻转图标的这个属性。

为了解决这个问题,在图像本身上重新定义从左到右。

    <StackPanel 
        Orientation="Horizontal" 
        FlowDirection="RightToLeft">
        <Button>
            <Image FlowDirection="LeftToRight">
                <Image.Style>
                    <!-- etc etc -->
                </Image.Style>
            </Image>
       </Button>
    </StackPanel>

关于WPF 按钮图标被镜像,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20911471/

相关文章:

c# - 忽略特定控件及其子控件的全局样式

.net - 如何在控制台应用程序中的 WPF MediaElement 上播放视频

json - 为什么我在快速解析时没有在按钮操作中获取所有 cellForRowAtindexPath 文本字段值

iOS - 通过按钮更改用户的语言

button - 在 Notepad++ 中创建新的快捷方式

wpf - 扩展 WPF 工具包 RichTextBox 垂直显示文本

WPF 后台渲染控件

wpf - 将 RichTextBox 绑定(bind)到字符串

c# - 如何让操作事件在包含 ScrollViewer 子元素的元素上起作用

c# - 如何使用文件URL机制在Metro中播放音乐