Images are not sharp in selected TabItem

戏子无情 提交于 2019-12-08 15:24:39

问题


I have a TabControl. The header of each TabItem contains a StackPanel with an icon and a Label.

<TabControl>
  <TabItem>
    <TabItem.Header>
      <StackPanel Orientation="Horizontal">
        <Image Source="/LoginPanel;component/Icons/icoLogin.ico"</Image>
        <Label VerticalContentAlignment="Center">Login</Label>
        </StackPanel>
      </TabItem.Header>
    </TabItem.Header>
    <!--some further code here-->
  <TabItem>
  <!--some further code here-->
<TabControl>

Each icon in each non-selected TabItem is displayed as expected. The Icon in the currently selected TabItem is somewhat cloudy. If I switch to another Tab, the de-selected Tab-Icon becomes clear; the new selected Icon becomes cloudy.

I already tried the following to solve this:

SnapsToDevicePixels="True"

but nothing happens

or

Width="32" Height="32"

or

Stretch="None"

to prevent scaling. All of this without any effect. Can some please give me a hint? Thanks in advance


回答1:


This works for me:

<Image Source="/LoginPanel;component/Icons/icoLogin.ico"
       RenderOptions.BitmapScalingMode="NearestNeighbor"</Image>



回答2:


Consider setting 'RenderOptions.EdgeMode' to 'Aliased' too.

<Image Source="/LoginPanel;component/Icons/icoLogin.ico"
       RenderOptions.BitmapScalingMode="NearestNeighbor"
       RenderOptions.EdgeMode="Aliased"/> 

See Image in WPF getting blury here on SO.



来源:https://stackoverflow.com/questions/5401141/images-are-not-sharp-in-selected-tabitem

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