Silverlight TextBlock 可以容纳多少个字符?

发布于 2024-11-18 22:31:47 字数 736 浏览 4 评论 0原文

我正在尝试将最终用户许可协议(EULA)放入 WP7 silverlight 文本块控件中。但是,它不断截断我的文本。为什么会发生这种情况? WP7 silverlight 文本块可以容纳的文本大小或字符数是否有限制?

下面是我在 xaml 方面所做的示例(xaml 周围的其余部分是自动生成的默认值)。

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

我也尝试过使用文本框,但现在,我什至无法在文本框中滚动。我也已明确将 VerticalScrollBarVisibility 设置为 Visible,但我仍然无法向下滚动 TextBox。事实上,我什至没有看到垂直滚动条。我不知道这个观察是否是因为我仍在通过模拟器查看用户界面。

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小ぇ时光︴ 2024-11-25 22:31:47

UIElement 在任一方向(高度或宽度)上都不能大于 2048 像素。任何超出此区域显示的内容都不会显示。 不过,在可视化树中保留了该内容所在的空间。

解决此问题的方法是使用多个元素来显示大量文本。

更新
我已经编写了自己的解析器来动态显示此类内容。理想情况下,尽管您不会在运行时处理大块文本。当文本包含链接(指向其他页面、网络内容或电子邮件启动器)时,情况可能会更加复杂。

当想要显示 EULA 或任何大段文本时,您不会想让用户轻松阅读和导航。毕竟,您要包含希望用户阅读的文本。

如果您在设计时有文本,您应该抓住机会确保其布局正确,并且为不同部分使用单独的 TextBlock,并适当地设置标题和子标题的样式可以帮助您做到这一点。

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.

倒数 2024-11-25 22:31:47

这可能有几个原因 - 您的文本块的高度可能受到另一个控件的限制,您应用于文本的样式可能会导致它......

您可以发布您的源代码吗?

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?

π浅易 2024-11-25 22:31:47

我想与你分享这段代码。它创建许多 TextBlock 并作为子项添加到 Stackpanel。您可以在 Scroll 查看器中创建 Stackpanel,因为 Scrollvewers 只能直接获取单个子元素。

    //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;
    }

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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文