0

I have the following ListView in my xaml layout:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0">
        <TextBlock Text="{StaticResource AppName}" Style="{StaticResource TitleTextBlockStyle}"/>
    </StackPanel>

    <StackPanel Grid.Row="1">
        <ListView x:Name="lstStatus">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="12">
                        <Image Source="ms-appx:///Assets/Logo.png" Margin="12" Width="150" Height="150"></Image>

                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding Path='Fullname'}" Style="{StaticResource ListViewItemSubheaderTextBlockStyle}"></TextBlock>
                            <TextBlock Text="{Binding Path='FormattedCreationTime'}" TextWrapping="WrapWholeWords"></TextBlock>

                            <TextBlock Text="{Binding Path='Text'}" Style="{StaticResource ListViewItemContentTextBlockStyle}" TextWrapping="WrapWholeWords" Margin="12"></TextBlock>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>

</Grid>

However, I met two problems:

  • The list is not scrollable when it is longer than the screen.
  • The TextBlocks does not wrap at all although I already set TextWrapping.

I am pretty new to Windows Phone design. Please tell me where did I do wrong.

1 Answer 1

1

The StackPanel takes as much space as it needs. As the ListView grows, the StackPanel expands to allow it to grow, hence you cannot scroll to see the items you don't see on the screen.

Put the ListView in a Grid or limit the Height of the StackPanel.

<Grid Grid.Row="1">
    <ListView x:Name="lstStatus">
    ...

Similar problem occurs in your ItemTemplate, and the fix is also similar.

<DataTemplate>
    <Grid Margin="12">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Image ...

        <StackPanel Grid.Column="1">
            <TextBlock ....
        </StackPanel>
    </Grid>
</DataTemplate>
Sign up to request clarification or add additional context in comments.

1 Comment

Nice, it works. However, may I ask if it affects performance much? Since every ListItem will have to attach a Grid and a StackPanel?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.