Windows Phone 7 TextBlock TextWrapping在列表框中不被接受 [英] windows phone 7 TextBlock TextWrapping not honored in listbox

查看:109
本文介绍了Windows Phone 7 TextBlock TextWrapping在列表框中不被接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框定义为:

I have a listbox defined as :

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox x:Name="myListBox" Width="468" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.Template>
                <ControlTemplate>
                    <ScrollViewer Width="468">
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </ListBox.Template>
        </ListBox>
    </Grid>

在代码中,我创建了多个textBlocks作为列表框项,并在每个textBlock中启用了textWrapping.

In the code, I create multiple textBlocks as the Listbox Items with textWrapping enabled in each textBlock.

       for (int i = 0; i < everyLine.Length; i++)
        {
            TextBlock txtBlock = new TextBlock()
            {
                TextWrapping = TextWrapping.Wrap,
                Name = "textBlock" + i,
                Foreground = textBrush,
                FontSize = 20,
                Text = everyLine[i]
           };

            this.myListBox.Items.Add(txtBlock);
        }

但是,任何文本块中的文本都没有被包裹.

But, none of the text in any of the text blocks gets wrapped.

有人可以让我知道以上在列表框中定义textBlocks的方法是否不正确吗?

Can somebody please let me know if the above way of defining textBlocks in listbox is incorrect?

推荐答案

+1来获取德里克的答案

+1 for Derek's answer

此外,请小心使用ListBox中的<StackPanel>.默认情况下,ListBox使用<VirtualizingStackPanel>,这非常重要,因为在显示长列表时,它使用的UI资源(内存)大大减少.

Also, please be careful using the <StackPanel> in your ListBox. By default, the ListBox uses a <VirtualizingStackPanel> and this is very important as it uses significantly less UI resources (memory) when displaying long lists.

这篇关于Windows Phone 7 TextBlock TextWrapping在列表框中不被接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆