How to add scrolling to a text box in a Windows 8 application?

I want to add a scroll viewer to a text box in a Windows 8 application. So that the user can scroll their long text

+4
source share
2 answers

Add scrollviewer to XAML. Then set the scrollviewer fields by cutting and pasting the text into the text box, and set the height and width of the auto text box.

+3
source

I just rewrote what Harsheath explained and added some photos and code.

  • Add scrollviewer to your xaml
  • Select a margin in Scrollviewer (best way: click the TestViewer-Code button in XAML to select it)
  • Set Margin Values ​​for Auto
  • Insert (in XAML) a text field and paste it into the Scrollviewer tag
  • Set the height and width of the text box in Auto
  • done!

XAML:

 <Page x:Class="testapp.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:newcalapp_winrt" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0,4,0,-4"> <Button Click="showText" Content="ShowText" x:Name="btn" Width="200" Height="56" Margin="1037,620,0,92"></Button> <ScrollViewer x:Name="outputTextBoxScrollViewer" Margin="57,200,700,400"> <TextBox x:Name="outputTextBox" AcceptsReturn="True"/> </ScrollViewer> <ScrollViewer x:Name="outputTextBlockScrollViewer" Margin="57,450,700,169"> <TextBlock x:Name="outputTextBlock"/> </ScrollViewer> </Grid> </Page> 

WITH#:

 namespace testapp { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } void showText(object sender, RoutedEventArgs args) { //OutputString String outputString; //Random number Random randomizer = new Random(); int randomNumber = randomizer.Next(0,100000); //Some magic with Dates :) Not important! ... outputTextBox.Text = outputString; outputTextBlock.Text = outputString; } } } 

ScrollViewerExample

http://i.stack.imgur.com/2qDyJ.png ">

0
source

All Articles