LongListSelector not scrolling - xaml

I am having trouble getting my long list selector to work properly. When the list is taller than the screen, the long list selector stays static and I am unable to scroll to see all of the items.
Any thoughts?
<phone:PivotItem Header="{Binding Path=LocalizedResources.ApplicationsHeader, Source={StaticResource LocalizedStrings}}" x:Name="applicationsPivotItem">
<Grid x:Name="applications" Grid.Row="1">
<phone:LongListSelector x:Name="MainLongListSelector" ItemsSource="{Binding Items}" SelectionChanged="MainLongListSelector_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</phone:PivotItem>

Fix the Height of the Grid
<Grid x:Name="applications" Grid.Row="1" Height="400">
...long list code...
</Grid>

I had a similar issue where my panoramaItem was defines as below:
<phone:PanoramaItem>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<phone:LongListSelector x:Name="SpeciesList" Grid.Row="0">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,-6,0,12">
<TextBlock Text="{Binding PrimaryName}"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</phone:PanoramaItem>
By changing the RowDefinition to use * instead of Auto, my scrolling issues was resolved! As shown below.
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

I had the same issue with the LongListSelector not scrolling. In the end it was OpacityMask="White" that was set in LongListSelector that was causing the issue as per this question
Also as per Mattias I didn't have to set a specific Height, as long as the grid RowDefinition was set to *.

Related

C# UWP - The first image inside ListView is incorrectly sized

I have a simple layout that basically displays a list of items in ListView using an ItemsWrapGrid as the panel template. The problem I am having is that the first image in the ListView is always bigger than the rest, even with a fixed width / height set. I am completely stumped.
An image of the problem:
The ListView XAML is:
<ListView ItemsSource="{Binding Currencies}" ItemTemplate="{StaticResource PortfolioCurrencyTemplate}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" Width="Auto" Height="Auto"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
The data template:
<Page.Resources>
<DataTemplate x:Key="PortfolioCurrencyTemplate" x:DataType="viewModels:PortfolioViewModel">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="2"
Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Grid.ColumnSpan="1" MaxWidth="100" MaxHeight="100" Source="https://www.cryptocompare.com/media/19633/btc.png"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Name}" VerticalAlignment="Center"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Symbol}" VerticalAlignment="Center"/>
<TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding LastPrice}" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</Page.Resources>
Instead of using ListView and changing ItemsPanelTemplate to create a GridView Effect and tackle issues one by one, I would suggest you switch to AdaptiveGridView.
You can install Nuget Package for UWP Community Toolkit from Here
Add below namespace to your page
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
Now your ListView needs to be replaced like below.
<controls:AdaptiveGridView ItemsSource="{Binding Currencies}"
ItemTemplate="{StaticResource PortfolioCurrencyTemplate}"
DesiredWidth="250"/>
Output from Designer
Good Luck.

ListView is not Scrollable

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.
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>

LongListSelector adjust based on screen width

I am new to windows phone 8 development and i have a very basic question i believe.
I wish to make my LongListSelector have 100% width and height but all the things i have tried didnt work.
I have tried Auto, * etc but nothing seems to do it.
Here is my code:
<!--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 Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=LocalizedResources.SetupsPageTitle, Source={StaticResource LocalizedStrings}}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector HorizontalAlignment="Left" Width="400" Height="400"
VerticalAlignment="Top"
Name="lstSetups" ItemsSource="{Binding BusRouteSetups}"
SelectionChanged="lstSetups_SelectionChanged"
LayoutMode="List">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Margin="0,10,0,10" Background="Coral">
<TextBlock TextWrapping="Wrap" Margin="5" FontWeight="Bold" Text="{Binding Details.Title}" />
<TextBlock TextWrapping="Wrap" Margin="5" Text="{Binding Details.Description}" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</Grid>
Any help will be much appreciated.
Use HorizontalAlignment = Stretch (also Vertical), then Width and Height of LLS will be set to maximum space that is available to that Control:
<phone:LongListSelector HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Name="lstSetups" ItemsSource="{Binding BusRouteSetups}"
SelectionChanged="lstSetups_SelectionChanged"
LayoutMode="List">
Note that it's maximum height will be determined by Grid (parent of Control). While you have set RowDefinition's Height to * - it means that it will use all the remaining height of the screen (remaining - some space is used by first row (set to auto) - StackPanel with title).
HorizontalAlignment="Left" Width="400" Height="400" VerticalAlignment="Top"
Just remove this part of your code and then the control should be sretched automatically.

Windows Phone 8 TextBlock cutting text off XAML

I have the following XAML code:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="#FFE8E8E8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,0" >
<TextBlock x:Name="AppName" Text="Agent" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0" Foreground="Black" />
<TextBlock x:Name="PageName" Text="agent audit" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Height="100" Foreground="Black"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Background="White"/>
<ScrollViewer HorizontalAlignment="Left" Margin="0,0,0,0" Grid.Row="1" VerticalAlignment="Top">
<TextBlock x:Name="auditText" HorizontalAlignment="Left" Margin="0,0,0,0" Grid.Row="1" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Foreground="Black" Padding="10"/>
</ScrollViewer>
</Grid>
When the page comes into view I assign the TextBlock with the contents of an API Call (audit log text), and this gets quite long.
However, currently it cuts off all text below the screen height. I have the TextBlock and ScrollView set to Auto layout height/width.
I can even see the top of the next line of text, when I scroll the rest doesn't appear. Quite hard to screenshot too as you only see the issue when scrolling, and whilst scrolling I can't take a screenshot :/
Any ideas where I'm going wrong?
I've read numerous posts on this site but nothing quite hit what I was after.
Thanks.
This ended up working for me:
<ScrollViewer Height="Auto" Grid.Row="1">
<TextBlock x:Name="auditText" Text="TextBlock"
VerticalAlignment="Top" Foreground="Black" Margin="0,10,0,0" Grid.Row="1" Padding="20" TextWrapping="Wrap">
</TextBlock>
</ScrollViewer>
Setting the ScrollViewer height to AUTO

ScrollViewer not working in windows phone with dynamic components

I have a stackpanel which sometimes contains more data than can fit on the screen. When this happens I'm unable to scroll down to see the rest of the list. So I added a ScrollViewer to fix this but I'm unable to get it working. This is the code:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Height="500" Name="Scroller" VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical" Name="Stack" Height="2000">
<TextBlock Text="{Binding BookableExplanation}" Foreground="#336699" TextWrapping="Wrap"/>
<Button Visibility="{Binding ShowLinkToSite, Converter={StaticResource BooleanToVisibilityConverter}}" cal:Message.Attach="[Event Click] = [Action OpenStuntOnWebAsRegularOffer]" Foreground="#FFFFFF" Background="#336699" BorderThickness="0">neckermann.be</Button>
<ListBox x:Name="DepartureDates" MinHeight="2000"
cal:Message.Attach="[Tap]=[Action OpenStuntOnWeb(DepartureDates.SelectedItem)]">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding}" Background="#336699" Margin="0,10,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="430"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,10,10,10">
<TextBlock Text="{Binding Date, StringFormat='dd/MM/yyyy'}" Foreground="#FFFFFF" TextWrapping="Wrap" TextAlignment="Center"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</ScrollViewer>
</Grid>
Any ideas ? On other views I just have text that scrolls fine, it's only when adding items dynamically that I ran into issues. Saw some posts here also about problems with the scrollviewer but followed those advice such as setting scrollviewer height lower than the stackpanel but didn't work. It's probably something really simple but can't find it :) It does the scrolling movement but just doesn't allow me to go down.
Thanks,
Jorn
I managed to fix it by reworking my XAML. It seems the stackpanel was the problem. Behavior is slightly different now but I can live with it.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="0,0,0,5">
<TextBlock Text="{Binding BookableExplanation}" Foreground="#336699" TextWrapping="Wrap"/>
<Button Visibility="{Binding ShowLinkToSite, Converter={StaticResource BooleanToVisibilityConverter}}" cal:Message.Attach="[Event Click] = [Action OpenStuntOnWebAsRegularOffer]" Foreground="#FFFFFF" Background="#336699" BorderThickness="0">neckermann.be</Button>
</StackPanel>
<ListBox Grid.Row="1" x:Name="DepartureDates"
cal:Message.Attach="[Tap]=[Action OpenStuntOnWeb(DepartureDates.SelectedItem)]">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding}" Background="#336699" Margin="0,10,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="430"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Orientation="Vertical" Margin="10,10,10,10">
<TextBlock Text="{Binding Date, StringFormat='dd/MM/yyyy'}" Foreground="#FFFFFF" TextWrapping="Wrap" TextAlignment="Center"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
Listbox has inbuilt Scroll viewer. So if you manually add scroll viewer, both controls will fight each other.
Do remove your scroll viewer. Will work.