【问题标题】:WPF Button icon gets mirrored, why?WPF 按钮图标被镜像,为什么?
【发布时间】:2014-01-21 14:01:50
【问题描述】:

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

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

当我想依赖按钮启用状态时,图标会被镜像。

<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>

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

什么负责镜像图标?

如果有人有提示以任何可能的方式进行调试,请随时为我指明正确的方向!

【问题讨论】:

    标签: wpf xaml button icons


    【解决方案1】:

    问题出在父 StackPanel 中。如果StackPanel 是从右到左定义FlowDirection,则Image 定义会继承此属性,从而导致图标翻转。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 2018-01-12
      • 1970-01-01
      • 2019-08-20
      • 2011-01-30
      相关资源
      最近更新 更多