在我的一生中,我无法让 gridsplitter 控件以我想要的方式运行。
在下面的布局中,我需要每个列表视图右侧的 gridspliter,它将扩展或收缩该列表视图并适当地调整其他列表视图的大小。
扩展器及其(绿色)面板不应调整大小。
请帮忙!这种控制快把我逼疯了。
MainWindow.xaml:
<Window x:Class="LayoutTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="400" MinWidth="1000">
<Grid Name="root" SizeChanged="root_SizeChanged">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xleft" Grid.Column="1" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
<ListView Grid.Column="2" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xmiddle" Grid.Column="3" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
<ListView Grid.Column="4" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xright" Grid.Column="5" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
</Grid>
</Window>
MainWindow.xaml.cs:
using System.Windows;
using System.Windows.Controls;
namespace LayoutTest
{
/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>
public partial class MainWindow : Window
{
Expander[] expanders;
Expander priority;
public MainWindow()
{
InitializeComponent();
expanders = new Expander[] {xleft,xmiddle,xright};
}
private void Expanded(object sender, RoutedEventArgs e)
{
if (sender is Expander) priority = sender as Expander;
if (root.ActualWidth > this.ActualWidth)
{
foreach (Expander ep in expanders)
{
if (ep.IsExpanded && priority != null && !ep.Name.Equals(priority.Name) )
{
ep.IsExpanded = false;
break;
}
}
}
}
private void root_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expanded(null,new RoutedEventArgs());
}
}
}