简体   繁体   English

如何阻止WPF TextBox的发展

[英]How to Stop WPF TextBox from growing

WPF TextBox Control grows when a long text has been typed in. 输入长文本时,WPF TextBox控件会增长。

This question has been already raised in Stackoverflow 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>

MaxWidth should do the trick. MaxWidth应该可以解决问题。 If not, what went wrong in your case? 如果没有,你的情况出了什么问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM