【问题标题】:How to stop a multiline textbox from moving the GridSplitter?如何阻止多行文本框移动 GridSplitter?
【发布时间】:2012-03-23 11:56:12
【问题描述】:

重现问题: 垃圾邮件(例如),直到您开始点击正确的网格分割器区域。 gridsplitter 被移动超过右侧最小宽度限制。

预期行为:在文本框中输入(类型/粘贴)时超出宽度限制不会移动网格分割器,但会立即激活滚动条。

条件

  • TextBox 必须可以水平和垂直滚动
  • TextBox 和 ScrollViewer 必须保持动态大小 - 没有最大宽度限制。这是因为在实际应用程序中,用户可以调整应用程序的大小,这会导致文本框被调整大小。

代码:

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

【问题讨论】:

    标签: .net wpf


    【解决方案1】:

    这会导致问题

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

    使用百分比值代替您的列定义:

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

    【讨论】:

      猜你喜欢
      • 2018-11-25
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 2014-11-21
      • 2017-11-17
      • 1970-01-01
      • 2011-09-15
      相关资源
      最近更新 更多