If you're programmatically adding items you'll also need to programmatically ensure that they are scrolled into view. You can do this with the LongListSelector.ScrollTo
method.
The LLS does not automatically scroll newly added items into view.
Update:
As a solution to the expanding textbox at the bottom of the LLS issue. You could instead do the following:
XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer x:Name="MyScrollViewer">
<StackPanel>
<ItemsControl x:Name="MyItems">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource PhoneTextExtraLargeStyle}"
TextWrapping="Wrap"
Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBox AcceptsReturn="True"
FontSize="36"
TextWrapping="Wrap"
VerticalScrollBarVisibility="Auto"
Text="{Binding}"
TextChanged="OnTextChanged"
Margin="0,0,0,48" />
</StackPanel>
</ScrollViewer>
</Grid>
Code behind:
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
this.InitializeComponent();
// Some sample existing items
this.MyItems.ItemsSource = new[] { "one", "two", "three", "four", "five" };
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
// This is a brute force attempt to scroll to the bottom of all content.
// You may want to be smarter about when this is done, such as when a "\r"
// is added to the end of the text in the textbox or the text is added
// such that it forces a new line. Beware text being changed in the middle
// of a large block of text as may not want that to trigger a scroll to the bottom.
this.MyScrollViewer.ScrollToVerticalOffset(double.MaxValue);
}
}
All a bit crude but hopefully you get the idea.
This uses a separate ItemsControl
and TextBox
inside a ScrollViewer
to mimic the LLS behaviour and will always expand keeping the bottom of the TextBox visible while still allowing scrolling of all content.
Obviously this won't work if you're heavily tied to the LLS though.