【问题标题】:WPF: Image stretched when placed in StackPanel in buttonWPF:图像在按钮中放置在 StackPanel 中时被拉伸
【发布时间】:2014-12-23 21:44:12
【问题描述】:

我正在 WPF 中制作一种工具栏(StackPanel 包含包含 StackPanel 的按钮,其中包含图像和 TextBlock...) 这是一个按钮的代码:

<Button x:Name="btnGraph" FontWeight="Normal" Background="{DynamicResource accentColor}" BorderBrush="{DynamicResource accentColor}">
    <StackPanel>
        <Image Source="Resources/diagnostic_chart1.png" Stretch="None"/>
        <TextBlock HorizontalAlignment="Center" Text="Graph"/>
    </StackPanel>
</Button>

如您所见,按钮中的图像被拉伸,但按钮外的相同图像代码(在容器 StackPanel 中),它可以正常工作:image

我尝试了很多东西,但没有任何效果。 有没有办法让它工作?

编辑:我也尝试将图像的 DPI 从 72 更改为 96,没有效果。

【问题讨论】:

    标签: c# wpf image button stretch


    【解决方案1】:

    图像在我看来没有拉伸;大小似乎合适。它实际上看起来像是跨像素边界渲染,使其外观模糊。尝试在你的根视觉上设置UseLayoutRounding="True"

    【讨论】:

      猜你喜欢
      • 2011-05-20
      • 2012-11-30
      • 1970-01-01
      • 2010-10-24
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多