Button template does not display image clearly

Here is my button template,

<Microsoft_Windows_Themes:ButtonChrome 
   x:Name="Chrome" 
   Background="{TemplateBinding Background}" 
   BorderBrush="{TemplateBinding BorderBrush}" 
   RenderDefaulted="{TemplateBinding IsDefaulted}" 
   RenderMouseOver="{TemplateBinding IsMouseOver}" 
   RenderPressed="{TemplateBinding IsPressed}">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Image 
               Source="{TemplateBinding ImageSource}" 

               RenderOptions.BitmapScalingMode="NearestNeighbor"

               SnapsToDevicePixels="True"

               HorizontalAlignment="Center"
               VerticalAlignment="Center"
              Stretch="None"
               />
        <ContentPresenter 
            Grid.Column="1"
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
            Margin="{TemplateBinding Padding}" 
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
            RecognizesAccessKey="True"/>
    </Grid>
</Microsoft_Windows_Themes:ButtonChrome>

Now, you can see on this subject https://stackoverflow.com/a/312618/ I tried ..

RenderOptions.BitmapScalingMode="NearestNeighbor"

At all levels, grid, chrome .. and tried various combinations of SnapsToDevicePixels, but the images just don't display correctly. I set Stretch = None, the image is centered, but why is it automatically stretched?

here is the result and its very frustrating.

Bad image in WPF http://akashkava.com/blog/wp-content/uploads/2009/12/BadButton.PNG

16x16, - , Windows Maginifier, , , 20x20, , , 16x16, Stretch = None, - , ?

+3
5

wpf, ​​Microsoft. , , .

+1

.

+1

, .

+1

, .

, WPF4. RenderOptions.BitmapScalingMode HighQuality .

(.. ) : UseLayoutRounding="True".

, Silverlight, .:)

- :

  • 1

  • 1

  • 1

Further information is found here: http://blogs.msdn.com/text/archive/2009/08/27/layout-rounding.aspx

+1
source

If you think your image is 16x16, but WPF seems to think it is 20x20, then you probably have a DPI problem in the image. Is your PNG image? Save it as jpg and see how it looks.

Link: http://www.hanselman.com/blog/BeAwareOfDPIWithImagePNGsInWPFImagesScaleWeirdOrAreBlurry.aspx

+1
source

Source: https://habr.com/ru/post/1725606/


All Articles