WPF文本框包装

WPF文本框包装,wpf,textbox,word-wrap,Wpf,Textbox,Word Wrap,我试图弄清楚如何让文本框包装其内容,但是情况与典型的“它不包装”场景不太一样。My textbox包含在Telerik RadTabControl实例中使用的DataTemplate中(使用ContentTemplatePresenter确定要显示的视图),DataTemplate的XAML如下所示: <DataTemplate x:Key="NotesTemplate"> <Grid> <Grid.RowDefinitions>

我试图弄清楚如何让文本框包装其内容,但是情况与典型的“它不包装”场景不太一样。My textbox包含在Telerik RadTabControl实例中使用的DataTemplate中(使用ContentTemplatePresenter确定要显示的视图),DataTemplate的XAML如下所示:

<DataTemplate x:Key="NotesTemplate">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Text="Use the box below to record any general notes associated with this item." Style="{StaticResource Default}" />
        <TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" GridRow="1" Margin="20" Text="{Binding Notes, UpdateSourceTrigger=PropertyChanged}" />
     </Grid>
</DataTemplate>
窗口大小本身并没有增长,所以如果我能得到窗口的宽度(减去一定的量以覆盖选项卡控件的宽度),我相信这是可行的

有什么想法吗

尽管视图中有滚动条

禁用水平滚动视图,因此它将被强制换行。您可以尝试在
文本框
本身或包装
网格
上禁用它

<DataTemplate x:Key="NotesTemplate">
    <Grid ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Text="Use the box below to record any general notes associated with this item." Style="{StaticResource Default}" />
        <TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Grid.Row="1" Margin="20" Text="{Binding Notes, UpdateSourceTrigger=PropertyChanged}" />
     </Grid>
</DataTemplate>


这不起作用,但这个SO链接让我99%的时间都在那里:。我唯一不知道的是,如果他们将窗口重新调整为较小的分辨率,框将保留原始宽度,但我不确定这对我是否重要,我倾向于不重要。@Digital L:我只是在这里运行了代码,它工作得很好(只是网格)。可能是其他包装控件弄乱了它。在一个有8列(其中一列设置为自动)的网格中,一个带有columnspan=“8”的文本框,包装不起作用,文本框会自动增大其大小;(如果有人想知道,当scrolbar由ListBox而不是DataGrid创建时,此修复程序也可以工作。或者至少它对我有效。最终通过另一个SO问题找到了最佳结果:。
<DataTemplate x:Key="NotesTemplate">
    <Grid ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Text="Use the box below to record any general notes associated with this item." Style="{StaticResource Default}" />
        <TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Grid.Row="1" Margin="20" Text="{Binding Notes, UpdateSourceTrigger=PropertyChanged}" />
     </Grid>
</DataTemplate>