How to stop WPF TextBox from growing

WPF TextBox Control grows as long text is entered.

This question has already been raised on Stackoverflow
and I've also answered several answers, but still I haven't found a correct answer that works.

The same problem was mentioned here , but there was no working solution for this kind of problem.

I spent enough time to solve this problem, please help me to solve this problem.

  <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>

      

+3


source to share


1 answer


MaxWidth should do the trick. If not, what went wrong in your case?



0


source







All Articles