MainPage.xaml
<Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock Text="Scroll Content Inside Textbox" Style="{StaticResource PhoneTextNormalStyle}" Margin="25,0,180,0"/> </StackPanel> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ScrollViewer Height="200" Name="scrlView" VerticalAlignment="Top"> <TextBox x:Name="txtBody" Width="200" AcceptsReturn="True" KeyUp="txtBody_KeyUp"/> </ScrollViewer> </Grid> </Grid>
MainPage.xaml.cs
private void txtBody_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Enter) { scrlView.UpdateLayout(); scrlView.ScrollToVerticalOffset(scrlView.ExtentHeight); } }
Trick:
(1) Named ScrollViewer as scrlView
(2) I wrote the code in the KeyUp event for the TextBox
(3) Whenever the user presses the Enter key, scroll through the TextBox through the code
Thank you all for your precious time and support.
Dev
source share