wpf - 具有多个兄弟姐妹的 WPF GridSplitter 无法按预期工作
问题描述
我四处搜索,并没有在论坛上找到类似的问题。我有以下 WPF 代码。
<Window x:Class="WpfApp5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp5"
mc:Ignorable="d"
Title="MainWindow" Height="238.788" Width="406.407">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox TextWrapping="Wrap" Text="TextBox1 should be resized while moving the GridSplitter"/>
<GridSplitter HorizontalAlignment="Stretch" Height="5" Grid.Row="1" />
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="Black">
<TextBlock Padding="5" Text="I want this black section have fixed height while moving the GridSplitter" Foreground="Aqua" VerticalAlignment="Center" />
</StackPanel>
<TextBox Grid.Row="3" TextWrapping="Wrap" Text="TextBox2 should be resized while moving the GridSplitter"/>
</Grid>
</Window>
当用户拖动网格拆分器时,只有两个文本框应该调整大小。但我得到的是这样的:
我怎样才能解决这个问题?
解决方案
将StackPanel
第二个和第二个移动TextBox
到一个Panel
:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox TextWrapping="Wrap" Text="TextBox1 should be resized while moving the GridSplitter"/>
<GridSplitter HorizontalAlignment="Stretch" Height="5" Grid.Row="1" />
<DockPanel Grid.Row="2">
<StackPanel Orientation="Horizontal" Background="Black" DockPanel.Dock="Top">
<TextBlock Padding="5" Text="I want this black section have fixed height while moving the GridSplitter" Foreground="Aqua" VerticalAlignment="Center" />
</StackPanel>
<TextBox TextWrapping="Wrap" Text="TextBox2 should be resized while moving the GridSplitter"/>
</DockPanel>
</Grid>
推荐阅读
- pandas - 在多个列中搜索最常见的值
- assembly - 是否可以从程序集中运行 .exe 文件
- azure-data-explorer - Azure Kusto 数据资源管理器 - 将持续时间转换为天
- reactjs - 反应过滤数组对象
- react-native - React Native Navigation 5 在 IOS 模拟器上工作,但在 Android 模拟器中不起作用
- shell - 如何在文件夹中递归地从具有特定扩展名的原始文件中删除扩展名?
- apache-kafka-streams - KafkaStreams 在使用窗口时处理延迟事件
- elasticsearch - Elasticsearch 限制结果如谷歌
- sql-server - 在多个地方提取部分字符串
- c++ - 没有超时的 C++ 条件变量