5

WPF TextBox Control grows when a long text has been typed in.

This question has been already raised in Stackoverflow
and I refereed few answers also, but still I didn't find the proper answer which is working.

Here same problem has been mentioned but no working solution for this kind of issue.

I have spend enough time to solve this, please help me to solve this issue.

  <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>
Community
  • 1
  • 1
Selva
  • 1,310
  • 2
  • 14
  • 31
  • 1
    possible duplicate of [WPF - How to stop TextBox from autosizing?](http://stackoverflow.com/questions/4465646/wpf-how-to-stop-textbox-from-autosizing) – Adriano Repetti May 22 '15 at 14:03

1 Answers1

-1

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

Denys Bulant
  • 316
  • 4
  • 10
  • 1
    Yes, I tried setting max width, but what would be case of large Monitor size. The alignment will not be good. – Selva May 25 '15 at 07:46
  • @Selva http://stackoverflow.com/a/387338/720901 There's a workaround, which also has its drawback. Otherwise, you may accept to sacrifice horizontal scrolling and set the ScrollViewer's HorizontalScrollBarVisibility to Disabled – Denys Bulant May 27 '15 at 20:43
  • I can't sacrifice. My requirement needs it. Thanks for your info. – Selva May 28 '15 at 09:15