我正在尝试构建一个 Windows Phone 8.1 应用程序,但有件事确实困扰着我: ![看这个]/image/80Hhb.png
正如您所看到的,当文本到达末尾时,文本框不会创建并转到新行。我应该怎么办?我尝试用谷歌搜索它,但找不到它(我确信我使用了错误的关键字,但我对此是新手)。
无论如何,这是我正在使用的 XAML 代码(其中有一些我在 Google 上找到但不起作用的代码)
查看“contentTextBox”:
<Grid x:Name="LayoutRoot" Background="WhiteSmoke">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TODO: Content should be placed within the following grid-->
<Grid Grid.Row="0" x:Name="TitleRoot" Margin="0,0,0,0">
<TextBox x:Name="titleTextBox" Text="Title"/>
</Grid>
<Grid Grid.Row="1" x:Name="ContentRoot" Margin="0,0,0,0">
<StackPanel Height="Auto">
<TextBox x:Name="contentTextBox" Text="" HorizontalAlignment="Stretch" VerticalAlignment="Top" AcceptsReturn="True" Width="Auto"/>
</StackPanel>
</Grid>
</Grid>
最佳答案
打开 TextWrapping 有帮助!
<TextBox x:Name="contentTextBox"
TextWrapping="Wrap"
Text=""
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AcceptsReturn="True"
Width="Auto" />
这意味着 - 当水平空间不足时,换行到另一行。
关于wpf - 在 WP8.1 XAML 中自动向 TextBox 添加换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24461161/