0
votes

I'm trying to show text in page of application in 3 textblocks. I want to scroll this because the text is dynamically changed and it depends on what we choose in previous page. When I did this like that:

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="Asystent Barmana" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock Name="PageName" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
    <ScrollViewer Name="Scroller"  HorizontalAlignment="Center" Height="auto" Margin="12,10,10,-1055" Grid.Row="1" VerticalAlignment="Top" Width="460" ManipulationMode="Control" MaxHeight="2500" >
        <StackPanel HorizontalAlignment="Left" Height="auto" VerticalAlignment="Top" Width="460">
            <TextBlock Name="MissingSkladnik" TextWrapping="Wrap" Height="auto" FontSize="24"/>
            <TextBlock Name="Skladniki" TextWrapping="Wrap" Height="auto" FontSize="24"/>
            <TextBlock Name="Przepis" TextWrapping="Wrap" Height="auto" FontSize="24"/>
        </StackPanel>
    </ScrollViewer>

</Grid>

and the text is not so long it work fine. But in several cases the text is longer and some of text is cut off. When I change StackPanel height to, let's say 1950, it dispaly fine, but when I have shorter text, on the end of page is a black nothing to scroll :/ Any thoughts?

PS. I apologize for my english, it's been a while since I used it ;)

Edit:

I read comments and I change stackpanel to grid. I did it like that:

<ScrollViewer Name="Scroller"  HorizontalAlignment="Center" Height="auto" Margin="12,10,10,-1055" Grid.Row="1" VerticalAlignment="Top" Width="460" ManipulationMode="Control" MaxHeight="2500" >
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock Name="MissingSkladnik" TextWrapping="Wrap" Height="auto" FontSize="24" Grid.Row="0"/>
            <TextBlock Name="Skladniki" TextWrapping="Wrap" Height="auto" FontSize="24" Grid.Row="1"/>
            <TextBlock Name="Przepis" TextWrapping="Wrap" Height="auto" FontSize="24" Grid.Row="2"/>
        </Grid>
    </ScrollViewer>

It doesn't work either. If I set the height of stackpanel it works, but when there is small amount of text it doesn't look nice. User can srcoll black empty screen :/

1
Can you try with a grid rather than a stackpanel?Kevin Gosse
set some height to your stackpanel..then tryloop
I would first try with a grid like @KooKiz said.Kajzer

1 Answers

2
votes

A StackPanel will not resize its content in the same way that a Canvas will not resize its content. However, a Grid control can resize its contents. Try replacing this:

<StackPanel Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
    <TextBlock Text="Asystent Barmana" Style="{StaticResource PhoneTextNormalStyle}"/>
    <TextBlock Name="PageName" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

with this:

<Grid Name="TitleGrid" Grid.Row="0" Margin="12,17,0,28">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <TextBlock Grid.Row="0" Text="Asystent Barmana" 
        Style="{StaticResource PhoneTextNormalStyle}"/>
    <TextBlock Grid.Row="1" Name="PageName" Text="page name" Margin="9,-7,0,0" 
        Style="{StaticResource PhoneTextTitle1Style}"/>
</Grid>

UPDATE >>>

In WPF, setting explicit Height and/or Width dimensions and/or Margins will stop a Control from sizing itself. If you want the ScrollViewer to re-size itself to the size of its content, try remove the explicit layout and dimension values that you have set, eg. Margin.