Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:21:49+00:00 2026-06-07T00:21:49+00:00

I’ve been trying to get something working in a windows 8 metro style application,

  • 0

I’ve been trying to get something working in a windows 8 metro style application, and I just can’t get the right properties for it to work. Here’s what I want to happen:

I’ve got a ScrollViewer containing a StackPanel. RichTextBoxes are added to the stack panel (streaming text data from a server). It works like a console, effectively. So my layout roughly looks like this:

<ScrollViewer>
  <StackPanel x:Name="outputStackPanel"/>
</ScrollViewer>

My desired behavior is this:
I want the text to scale uniformly in the horizontal direction for the screen size, and then scroll vertically in the ScrollViewer. That is to say, the font I am using is a fixed width font, and no matter what the screen size is, I want the same number of ascii characters to appear.

In addition, I have an option in the app to wrap text or not to wrap text to the screen. This means, when the text is wrapping, it should wrap to the fixed screen width, but when it is not, the ScrollViewer should be scrollable horizontally, but at any point roughly the same number of characters should be visible horizontally while scrolling.

I’ve tried a couple of methods to do this, and none of them have been successful. I’ve tried adding a ViewBox, like so:

<ScrollViewer>
  <Viewbox Stretch="UniformToFill" StretchDirection="UpOnly">
    <StackPanel x:Name="outputStackPanel" />
  </ViewBox>
</ScrollViewer>

While this seems to work in terms of getting the text to appear at the right size, it doesn’t allow the text to wrap when text wrapping is on. The content is simply cut off on the right side.

My current workaround is to check the screen resolution and make a rough estimate for the font-size to get it to display correctly, but this is not ideal because it’s not exact, so different resolutions get vastly different numbers of visible characters, and for the purposes of this application the number of visible characters is significant.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:21:50+00:00Added an answer on June 7, 2026 at 12:21 am

    I’ve been able to get it to work, but unfortunately I don’t think there’s an answer that will work automatically for any font. I could be wrong, but here’s how I got it to work:

    I picked a fixed-width font (Consolas) and a particular size. I don’t think the size matters.

    After picking the font size, I put the RichTextBlock into a ViewBox and figured out exactly what WIDTH I needed to set the RichTextBlock to get the exact number of characters (or columns) I wanted on the screen. At a font size of 13.333, to get exactly 60 columns I needed a width of 440.

    Using 13.333 font size and a fixed width of 440 inside a ViewBox, I am always able to get exactly 60 columns no matter what screen resolution or orientation and the text wraps.
    Now that that was working, I needed to tackle your problem doing the same thing with word wrap disabled.

    You wanted the text to be able to flow off the screen and allow the user to pan in either direction, but you always wanted a fixed number of columns (in my example, 60). To accomplish this, I removed the fixed width from the RichTextBox and figured out what zoom level the ScrollViewer needed to be set to in order to always get 60 columns wide. It turns out the zoom level is the current screen width divided by 440 (the magical width I came up with above for this particular font and size).

    So, here is the xaml:

        <ScrollViewer x:Name="Scroller" ZoomMode="Disabled" HorizontalScrollBarVisibility="Visible" >
            <RichTextBlock x:Name="TextBlock">
                <Paragraph FontSize="13.333" FontFamily="Consolas">
                    <Run Text="…" FontFamily="Consolas"/>
                </Paragraph>
            </RichTextBlock>
        </Viewbox>
    </ScrollViewer>
    

    For word wrap ON:

    TextBlock.Width=440
    Scroller. ZoomToFactor(1.0f)
    

    For word wrap OFF:

    TextBlock.Width=Auto
    Scroller.ZoomToFactor((float)Window.Current.Bounds.Width / 440);
    

    It’s important to change the zoom level whenever the window size changes. This could be because the user rotated the device, because they connected an external monitor, because you’ve gone into snapped view, etc. You can get notified whenever this happens by subscribing to the Window.Current.SizeChanged event. Inside the event, be sure to use the parameter passed to you because the window hasn’t actually changed size yet at this point. So:

    void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
        Scroller.ZoomToFactor((float)e.Size.Width / 440);
    }
    

    Finally, obviously the Width of 440 is tied to that particular font, font size and the fact that I always want 60 columns displayed. Once I figured it out, it should never change on any display size as long as I use the same font and font size. If you want to allow the user to pick different fonts, you’re going to have to figure out a way to calculate that dynamically. I couldn’t find any answer for this in my 20 minutes of searching. Maybe someone else can find that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.