wpf - 在 WP8.1 XAML 中自动向 TextBox 添加换行符

标签 wpf xaml windows-phone-8.1

我正在尝试构建一个 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/

相关文章:

c# - WPF 的 IsKeyboardFocusWithin 属性的 UWP 替代方案

XAML 绑定(bind)字符串连接

c# - Azure REST API - 服务器无法进行身份验证

windows-runtime - 如何在 Windows Phone 8.1 中每分钟更新一个自定义图像动态磁贴?

c# - 值不能为空,参数名称 : path

wpf - WPF 多线程如何工作?

c# - 调用嵌入在 Winforms-Application 中的 Unity-Application 上的函数

WPF DataGrid 为每个列集添加单独的边框

c# - WPF绑定(bind)(使用触发器)不能从文本框工作到标签

javascript - 失败的 Promise 被 Application.onerror 函数捕获