Rub*_*aus 11 wpf textbox word-wrap
我试图弄清楚如何让文本框包装其内容,但情况与典型的"它不包装"场景并不完全相同.我的文本框包含在一个DataTemplate中,该DataTemplate在Telerik RadTabControl实例中使用(使用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>
Run Code Online (Sandbox Code Playgroud)
我之所以说它不属于正常的"它没有换行"的情况是它用来换行,直到我不得不将视图更改为可调整大小以支持应用程序将运行的不同屏幕大小.当我这样做时,TextBox停止换行,因为(大概)当用户输入TextBox说"我需要更多空间"的东西时,父母必须这样,并且盒子无限期地向右延伸(尽管视图获得滚动条).我尝试使用Binding/RelativeSource设置MaxWidth,但由于父设计专门用于增长,因此该方法不起作用.我需要做的是盒子应该是'包含父母' VisibleWidth的宽度.意思是,如果Window本身是1024x768,TextBox的MaxWidth应该是1024,之后的任何文本都会自动换行,但是如果Window增长到1280x1024,则该框现在应该是1280并且文本换行相应.我用这个绑定表达式尝试了这个场景,但没有运气:
MaxWidth="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ActualWidth}"
Run Code Online (Sandbox Code Playgroud)
窗口大小本身没有增长,所以如果我可以得到窗口的宽度(减去一定量以覆盖TabControl的一部分的选项卡的宽度)我相信这将工作.
有任何想法吗?
Mic*_*elS 16
虽然视图获得滚动条
禁用水平scrollView,因此将强制换行.您可以尝试在TextBox自身或包装上禁用它Grid.
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34983 次 |
| 最近记录: |