【发布时间】:2015-09-07 12:05:17
【问题描述】:
考虑以下 XAML 示例。
- 我有一个 ScrollViewer。如果窗口对于网格来说太小,滚动条将可见。
- 在 ScrollViewer 中是 Grid。网格中的所有项目都应拉伸到网格的列宽。
- 现在有文本框(文本很长)。
我的问题是,如果文本越来越大,文本框会越来越大。但我只是希望文本框适合网格空间。
如何禁用带有大文本的文本框调整大小?
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="26" />
<RowDefinition Height="26" />
<RowDefinition Height="26" />
<RowDefinition Height="26" />
<RowDefinition Height="26" />
<RowDefinition Height="26" />
<RowDefinition Height="10*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" MinWidth="130" />
<ColumnDefinition Width="130" />
</Grid.ColumnDefinitions>
<Label VerticalAlignment="Center" HorizontalAlignment="Left" Content="Label 1" Grid.Column="0" Grid.Row="0"/>
<TextBox x:Name="Tbox1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Text="asfas fasd fasdf asdf asdf asdf asdf asf safasdf asdf asdf fasasd fas f" TextWrapping="Wrap" Height="22" Grid.Column="1" Grid.Row="0" />
<Label VerticalAlignment="Center" HorizontalAlignment="Left" Content="Label 2" Grid.Column="0" Grid.Row="1"/>
<TextBox x:Name="Tbox2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Text="asfas fasd fasdf asdf asdf asdf asdf asf safasdf asdf asdf fasasd fas f" TextWrapping="Wrap" Height="22" Grid.Column="1" Grid.Row="1" />
</Grid>
</ScrollViewer>
【问题讨论】:
-
不确定是否理解您的问题,但如果您的文本框应始终为固定宽度,为什么不将其宽度设置为所需值?