Auto scale text

This topic contains 3 replies, has 2 voices, and was last updated by  Simon B 2 months, 1 week ago.

  • Author
    Posts
  • #96063

    Simon B
    Participant

    I have a xaml form with some text in a TextBlock, what is the best way to scale the text depending on the DPI and zoom setting people have on their monitors so the text will still be readable at 1600 x 900 and 800 x 600 but I can't find an AutoScaleMode to make the form dpi and zoom aware

    TextBlock HorizontalAlignment="Stretch" Margin="12,6,12,12" FontFamily="Arial" FontSize="32"
    Name="TextDisplay" VerticalAlignment="Stretch" Background="LightGray"
    Foreground="Black" TextAlignment="Center" FontStretch="Expanded">
    TextBlock

  • #96089

    Will Prather
    Participant

    I don't have the answer for that one as maybe I just haven't run into that yet. If you find an answer, I'd be interested to hear it.

    While this forum is great for PowerShell, your question is more specifically about WPF applications. In your case, you are just using PowerShell to create it. If you search around a wpf example on how to cover the taskbar even if it is pinned, you may be more likely to find an answer. In some cases, you may need to adapt the answer from a C# example.

  • #96146

    Simon B
    Participant

    Hi Will, I have come up with one solution, there will be better 🙂 I found if I wrapped the Textblock in a viewbox and another grid the text autoscales to resolution. The strange this is that on lower resolutions i.e. 800 x 600 the text is smaller than on higher resolutions. But hey I think I can live with that 🙂

    Viewbox Stretch="Fill" StretchDirection="Both" Margin="200" VerticalAlignment="Top" HorizontalAlignment="Left"
    Grid

    TextBlock HorizontalAlignment="Stretch" Margin="12,6,12,12" FontFamily="Arial" TextWrapping = "Wrap"
    Name="TextDisplay" VerticalAlignment="Stretch" Background="LightGray"
    Foreground="Black" TextAlignment="Center" FontStretch="Expanded"
    TextBlock

    Grid
    Viewbox

  • #96149

    Simon B
    Participant

    Also to cover the taskbar just add

    WindowState="Maximized"
    WindowStyle="None"

    Topmost="True"

You must be logged in to reply to this topic.