如何阻止 WPF TextBox 增长

Sel*_*lva 5 c# textbox resize wpf-controls

当输入长文本时,WPF TextBox 控件会增长。

这个问题已经在 Stackoverflow 中提出了
,我也参考了很少的答案,但我仍然没有找到正确的答案。

这里提到了同样的问题,但没有针对此类问题的有效解决方案。

我已经花了足够的时间来解决这个问题,请帮助我解决这个问题。

  <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <DockPanel LastChildFill="False" Grid.IsSharedSizeScope="True">
            <GroupBox DockPanel.Dock="Top" DataContext="{Binding Data, ValidatesOnNotifyDataErrors=False}">
                <GroupBox.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock  shell:Localization.VbeiTag="vbeiGeneralInformation" Text="General Information"/>
                    </DataTemplate>
                </GroupBox.HeaderTemplate>

                <Grid DockPanel.Dock="Top" Margin="0,0,0,3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" SharedSizeGroup="GroupA" />
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="Auto" SharedSizeGroup="GroupB" />
                        <ColumnDefinition Width="1*" />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <!--Code Prefix Label -->
                    <Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Content="Code"  ></Label>
                    <Label Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" Content="Name" ></Label>

                    <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Title" ></Label>
                    <Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Content="Long Reference"  ></Label>

                    <Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Content="Client Reference"></Label>
                    <Label Grid.Row="3" Grid.Column="2" HorizontalAlignment="Left" Content="Lead Sub-Business Unit" ></Label>

                    <!--Code Prefix Editor-->
                    <common:StudyCodeEditor Grid.Row="0" Grid.Column="1" DataContext="{Binding ValidatesOnNotifyDataErrors=False}"
                                        SuggestedStudyCodePrefixRange="{ViewModelBinding SuggestedStudyCodePrefixRange}"/>

                    <!--Study Name-->
                    <TextBox Grid.Row="0" Grid.Column="3" Margin="3" VerticalAlignment="Top"
                         Text="{Binding StudyName, UpdateSourceTrigger=PropertyChanged}" />

                    <!--Study Title -->
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="3" Grid.ColumnSpan="3" VerticalAlignment="Top"
                         Text="{Binding StudyOfficialTitle, UpdateSourceTrigger=PropertyChanged}" />

                    <!--Client Long Reference -->
                    <TextBox Grid.Row="2" Grid.Column="1" Margin="3" Grid.ColumnSpan="3" VerticalAlignment="Top"
                         Text="{Binding StudyClientLongReference, UpdateSourceTrigger=PropertyChanged}" />

                    <!--Client Study Reference-->
                    <TextBox Grid.Row="3" Grid.Column="1" Margin="3" VerticalAlignment="Top"
                         Text="{Binding ClientStudyReference, UpdateSourceTrigger=PropertyChanged}" />

                    <!-- Description -->
                    <TextBox Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="3"
                         Text="{Binding Description}" AcceptsReturn="True" DockPanel.Dock="Top"
                         TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Margin="3" Height="62"/>
                </Grid>
            </GroupBox>          
        </DockPanel>
    </ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

Den*_*ant -1

MaxWidth 应该可以解决问题。如果没有,您的情况出了什么问题?