开发者

textwrapping in silverlight 4 not working

开发者 https://www.devze.com 2023-03-13 15:20 出处:网络
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

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

精彩评论

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