WPF:奇怪的图像拉伸按钮 [英] WPF: Strange image stretching in Buttons

查看:160
本文介绍了WPF:奇怪的图像拉伸按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个按钮,每一个具有32×32像素的PNG图片。但奇怪的是,这两个按钮显示不同的大小(是的,我三重检查的图标是真正的32×32!)。在秒按钮的样子,这将是48×48像素的大小。最有趣的是,如果我省略了拉伸=无属性,该图标放大来填充几乎整个屏幕。

I have multiple buttons, each having a 32x32 pixels PNG image. The strange thing is, that both buttons show different sizes (Yes, I triple checked that icons are really 32x32!). The seconds button looks like as it would be 48x48 pixels in size. The funniest thing is, if I omit the Stretch="None" attribute, the icons are scaled up to fill nearly the whole screen.

我无法解释自己为什么会这样!

I cannot explain myself why this is happening!

    

    <ToolBar Name="toolBar1" DockPanel.Dock="Top">
        <Button Name="importButton" ToolTip="Import" Click="importButton_Click">
            <Image Source="Icons/Import.png" Stretch="None" />
        </Button>
        <Button Name="toggleDetails" ToolTip="Details for Item" Click="toggleDetails_Click">
            <Image Source="Icons/maximize.png" Stretch="None" />
        </Button>           
    </ToolBar>

    <StackPanel Name="stackPanel1" DockPanel.Dock="Top" Orientation="Horizontal" Margin="0,5,0,5">
        <Label  Name="label2" Content="Find"></Label>
        <TextBox  Name="tags" Width="400" KeyDown="tags_KeyDown" />
        <Button ToolTip="Find" Name="findItemsButton" Click="findItemsButton_Click">
            <Image Source="Icons/xmag.png" Stretch="None" />
        </Button>
        <CheckBox Content="Show Closed" Name="showClosedItemsCheckBox" VerticalAlignment="Center" Margin="10,0,0,0" Click="showClosedItemsCheckBox_Click" />
    </StackPanel>
    <TabControl  Name="tabControl" TabStripPlacement="Top">

    </TabControl>

</DockPanel>

推荐答案

这两个图像可能有不同的DPI。

The two images probably have different DPIs.

这篇关于WPF:奇怪的图像拉伸按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆