how many characters can a Silverlight TextBlock ho

2019-01-25 00:46发布

问题:

i am trying to put a end-user license agreement (EULA) into a WP7 silverlight textblock control. however, it keeps truncating my text. why is this happening? is there a limit on the text size or number of characters a WP7 silverlight textblock can hold?

below is an example of what i've done in terms of xaml (the rest of the xaml surrounding is the default that is auto-generated).

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <ScrollViewer>
        <TextBlock x:Name="tbMsg" TextWrapping="Wrap"/>
    </ScrollViewer>
</Grid>

i've also tried using a TextBox, but now, i can't even scroll within the TextBox. i've explicitly set the VerticalScrollBarVisibility to Visible too, but i still can't scroll down the TextBox. in fact, i don't even see the vertical scroll bar. i don't know if this observation is because i'm still viewing the UI via the emulator.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBox x:Name="tbMsg" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"/>
</Grid>

回答1:

No UIElement can be larger than 2048 pixels in either direction (height or width). Any content which would be displayed beyond this area isn't displayed. Space for where this content would be is reserved within the visual tree though.

The work around for this is to use multiple elements to display large amounts of text.

Update
I've written my own parsers for dynaically displaying content of this sort. Ideally though you won't be working with large blocks of text at runtime though. This can be further complicated when the text contains links (to other pages, web content or email launchers).

When wanting to display EULAs or any large piece of text, you won't want to make it easy for the user to read and navigate. Afterall you are including the text as you want the user to read it.

If you have the text at design time you should take the opportunity to ensure that it is laid out appropriately and using separate TextBlocks for different sections and styling headings and sub-headings appropriately can help you do this.



回答2:

It could be several things - the height of your textblock may be being constrained by another control, a style you have applied to the text may be causing it...

Can you post your source?



回答3:

I want to share with you this code. It creates a number of TextBlocks and add as children to Stackpanel. You can create a Stackpanel inside your Scroll viewer since Scrollvewers can only take a single child element directly.

    //constructor
    List<char> countStoryvar = new List<char>(); //to store the text Body
    private string incStorybody;
    private int textMax = 2000;    //You can modify this.

   //methods
 private void PlaceData()
    {
        incStorybody = "Your Story Source";
        int countStory = incStorybody.Count();
        countStoryvar = incStorybody.ToList();
        double countStoryd = double.Parse(countStory.ToString());
        if (countStoryd < textMax)
        {
            TextBlock txtBlock = new TextBlock();
            txtBlock.TextWrapping = TextWrapping.Wrap;
            readStackPanel.Children.Add(txtBlock);
        }
        else
        {
            double countStoryd2 = countStoryd / textMax;  //fetch divisions
            countStoryd2 = Math.Round(countStoryd2, 5);  //getting Real no
            string sountstring = countStoryd2.ToString();
            string[] split = sountstring.Split(new string[] { "." }, StringSplitOptions.None);     //to remove decimal
            int countStoryi = int.Parse(split[0]);
            int remainder = countStory - (textMax * countStoryi);
            int iterationtimestin = countStoryi + 1;
            for (int z = 0; z < iterationtimestin; z++)
            {
                int zlast = countStoryi - 1;
                int multiple = 0;
                int multiple1 = 0;
                int multiplecounter = 0;
                multiple = textMax * z;
                if (z == 0)
                {
                    multiplecounter = textMax;
                }
                else
                {
                    if (z == countStoryi)
                    {
                        multiplecounter = countStory;

                    }
                    else
                    {
                        multiple1 = z + 1;
                        multiplecounter = textMax * multiple1;
                    }
                }
                LoadStackPanel(multiple, multiplecounter);
            }
        }

    }
    private void LoadStackPanel(int starting, int ending)
    {
        TextBlock txtBlock = new TextBlock();
        txtBlock.TextWrapping = TextWrapping.Wrap;
        for (int zi = starting; zi < ending; zi++)
        {
            incStoryInput = incStoryInput + countStoryvar[zi];
        }
        txtBlock.Text = incStoryInput;
        readStackPanel.Children.Add(txtBlock);
        incStoryInput = string.Empty;
    }