开发者

textwrapping in silverlight 4 not working

I want to do text wrap and show a vertical scroll bar when i have more than a line of text but the text is not getting wrapped at all. this is my xaml

<StackPanel Name="panel">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                </Grid.RowDefinitions>

                <StackPanel
                    Grid.Row="0"
                    Grid.Column="0"
                    Orientation="Horizontal"
                    Background="Yellow">

                <TextBlock  Text="Text:" />
                <ScrollViewer                                    
                    BorderThickness="0"
                    Height="33"                                    
                    VerticalScrollBarVisibility="Auto"                  开发者_运维知识库              
                    HorizontalScrollBarVisibility="Disabled">                    
                    <TextBlock TextWrapping="Wrap" Text="{Binding Name}"/>
                </ScrollViewer>
                </StackPanel>
            </Grid>
        </StackPanel>

Can someone tell me why the text won't wrap at end of screen ?

Thanks


What is happening here is that your internal StackPanel (and every StackPanel) doesn't constraint its children to the "visible" space in the StackPanel. So, the scrollviewer feels like having unlimited space and so is the textblock. The Grid itself can do it:

<StackPanel Name="panel">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TextBlock  Text="Text:" />
        <ScrollViewer Grid.Column="1"
                                    BorderThickness="0"
                                    Height="33"
                                    VerticalScrollBarVisibility="Auto"
                                    HorizontalScrollBarVisibility="Disabled">
            <TextBlock TextWrapping="Wrap"
                                    Text="YourText" />
        </ScrollViewer>
    </Grid>
</StackPanel>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜