简体   繁体   中英

How to stop a multiline textbox from moving the GridSplitter?

To reproduce the issue: Spam a letter (for example) until you start hitting the right gridsplitter area. The gridsplitter gets moved past the right side min-width limit.

Expected behaviour: Going over the width limit when typing (type/paste) into the textbox does not move the gridsplitter, but immediately activates the scrollbar.

Conditions

  • The TextBox must be horizontally and vertically scrollable
  • The TextBox and the ScrollViewer must remain dynamically sizable - no maxwidth limit. That's because in the real application, the user can resize the app, which results in the textbox being resized.

Code:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="10000*" MinWidth="25"/>
        <ColumnDefinition Width="8" />
        <ColumnDefinition Width="*" MinWidth="25" />
    </Grid.ColumnDefinitions>
    <ScrollViewer HorizontalScrollBarVisibility="Visible">
        <TextBox AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap" />
    </ScrollViewer>
    <GridSplitter Background="Black"
                  BorderBrush="White"
                  BorderThickness="1,0,0,0"
                  ResizeDirection="Columns"
                  HorizontalAlignment="Stretch"
                  VerticalAlignment="Stretch" Grid.Column="1" />
    <Grid Background="Red" Grid.Column="2" />
</Grid>

Thats causing problems

<ColumnDefinition Width="10000*" MinWidth="25"/>

Use percentage values for you column definition instead:

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width=".75*" MinWidth="25"/>
        <ColumnDefinition Width="8" />
        <ColumnDefinition Width=".25*" MinWidth="25" />
    </Grid.ColumnDefinitions>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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