WPF font scaling WPF font scaling wpf wpf

WPF font scaling


Try this: Render your text items like you would do it any other time:

  • TextBlocks contained in an 'ItemsControl'?
  • ListBox?

Place the whole shebang into a ViewBox and set it to scale appropriate to your needs. Look for Horizontal, Vertical or combined scaling properties.


This workaround might help:

    <ScrollViewer>    <Grid>        <Grid.RowDefinitions>            <RowDefinition Height="30*" MinHeight="30"/>            <RowDefinition Height="30*" MinHeight="30"/>            <RowDefinition Height="30*" MinHeight="30"/>        </Grid.RowDefinitions>        <Button Grid.Row="0" MaxHeight="100">            <Viewbox>                <TextBlock Width="{Binding ElementName=tbLonger,Path=ActualWidth}">T</TextBlock>            </Viewbox>        </Button>        <Button Grid.Row="1" MaxHeight="100">            <Viewbox>                <TextBlock Width="{Binding ElementName=tbLonger,Path=ActualWidth}">Test</TextBlock>            </Viewbox>        </Button>        <Button Grid.Row="2" MaxHeight="100">            <Viewbox>                <TextBlock Name="tbLonger">Test Longer String</TextBlock>            </Viewbox>        </Button>    </Grid></ScrollViewer>

The key is to set all textblocks the same width. In this case they all follow the longest textblock through binding.


I had to make an resolution independent application and made it with this answer here:tips on developing resolution independent application

with that your application is scaling (or zooming), depending on the resolution.