65.9K
CodeProject is changing. Read more.
Home

Improve WPF performance with RenderOptions

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.29/5 (5 votes)

Apr 11, 2014

CPOL
viewsIcon

20315

My original article link is here: http://www.codeproject.com/Tips/752333/Improve-WPF-performance-with-RenderOptions Introduction Too many articles have been presented on how to improve WPF performance with several global methods.

My original article link is here: http://www.codeproject.com/Tips/752333/Improve-WPF-performance-with-RenderOptions

Introduction

Too many articles have been presented on how to improve WPF performance with several global methods.

Here, we introduce another basic ways of improving WPF performance:

  • RenderOptions: Provides options for controlling the rendering behavior of objects.

Using the Code

For more details, please go to read MSDN (RenderOptions class). Here just for telling you with these, your application’s performance should be improved.

Here is an example. You could see the difference between the two:

In the code block, you can see that certain settings could be inherited by childs element in XAML element-tree:

         <StackPanel Grid.Column="0" Margin="5" 
                    TextOptions.TextRenderingMode="Grayscale"
                    RenderOptions.ClearTypeHint="Enabled"
                    RenderOptions.BitmapScalingMode="NearestNeighbor"
                    RenderOptions.EdgeMode="Aliased">
            <TextBlock Text="With RenderOptions and TextOptions" HorizontalAlignment="Center"
                       TextOptions.TextHintingMode="Fixed" TextWrapping="Wrap" Width="300" 
                       TextAlignment="Center"/>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Image Source="_AUT.png" Width="30" RenderOptions.ClearTypeHint="Enabled"
                   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                <Image Source="_CHE.png" Width="30" RenderOptions.ClearTypeHint="Enabled"
                   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                <Image Source="_CHN.png" Width="30" RenderOptions.ClearTypeHint="Enabled"
                   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                <Image Source="_DEU.png" Width="30" RenderOptions.ClearTypeHint="Enabled" 
                    RenderOptions.EdgeMode="Aliased"
                   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                <Image Source="_CHL.png" Width="30" RenderOptions.ClearTypeHint="Enabled" 
                    RenderOptions.EdgeMode="Aliased"
                   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                <Image Source="_BEL.png" Width="30" RenderOptions.ClearTypeHint="Enabled" 
                    RenderOptions.EdgeMode="Aliased"
                   RenderOptions.BitmapScalingMode="NearestNeighbor"/>
            </StackPanel>
            <Grid Margin="0,0">
                <Canvas Height="60" Width="60" VerticalAlignment="Center">
                    <Polygon Points="2,59 30,2 59,39" Fill="Red">
                    </Polygon>
                </Canvas>
            </Grid>
        </StackPanel>