当用户在文本框中输入时被包裹文本所困扰,使用“MaxWidth 来控制文本框并包裹文本但它缩小了文本框的大小。我不确定我必须如何拉伸它,即使我正在使用 HorizantalAlignment =" Stretch”,但它与其他文本框不匹配。
如果我不换行文本,那么如果文本大于文本框,则整个网格都会移动,这是否可以修复大小并换行。
这是我的 xaml 代码
<DockPanel Grid.Row="1">
<Grid Name="gLeftContent" Grid.Row="0" Background="Transparent" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="30" />
<RowDefinition Height="20"/>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="0"/>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="0" />
<RowDefinition Height="25" />
<!-- Row 14 -->
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<TextBox
Name="tbName"
Text="{Binding SelectedStory.Slug, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Width="{Binding ActualWidth, ElementName=tbName}" **//used ActualWidth but it shrinks the text box and doesn't match with the other text box.**
Grid.Column="1"
Grid.Row="5"
TextWrapping="Wrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbSlug_LostFocus"
>
<TextBox
Name="tbHeadline"
Text="{Binding SelectedStory.Headline, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
Grid.Column="1"
Grid.Row="6"
TextWrapping="Wrap"
d:LayoutOverrides="Height"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
LostFocus="tbHeadline_LostFocus"
/>
</TextBox>
<ItemsControl
Grid.Column="1"
Grid.Row="14"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.MetadataGenerateImagesRegion}"/>
</Grid>
</DockPanel>
提前致谢。