我的情况是我在标签内有2列。第二列可以隐藏。用图片可以更好地解释问题:
没有显示第二列的初始标签应该如下所示,所以它是正确的:
频道标签也应如此,这也是正确的:
但是当我使用网格分割器调整第二列的大小时,列表框保持固定宽度而不是拉伸。我希望它延伸:
现在,在调整第二个标签列表框的大小后,第一个标签有一个不需要的空白区域:
代码:
<TabControl x:Name="tcTabs" ItemsSource="{Binding Rooms, UpdateSourceTrigger=PropertyChanged}" Margin="5" BorderThickness="1" IsSynchronizedWithCurrentItem="True">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding Name}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding Messages}" DisplayMemberPath="Raw" Grid.Row="0" Grid.Column="0" BorderThickness="0" />
<GridSplitter ResizeDirection="Columns" VerticalAlignment="Stretch" Width="3" />
<ListBox ItemsSource="{Binding Users}" DisplayMemberPath="Nick" Visibility="{Binding Type, Converter={StaticResource UserListVisibilityConverter}}" Grid.Row="0" Grid.Column="1" BorderThickness="1,0,0,0" BorderBrush="#FFBBBBBB" Width="130" />
<TextBox Grid.Row="1" Grid.ColumnSpan="2" BorderThickness="0,1,0,0" BorderBrush="#FFBBBBBB" Height="22" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
如何解决此问题?
答案 0 :(得分:0)
首先,我会将GridSplitter放在自己的列中。其次,确保您的最终专栏也具有比例尺寸。第三,不要在最右边ListBox
设置固定宽度。如果您希望它具有最小宽度,请设置MinWidth
。所以你的XAML看起来像是:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding Messages}" DisplayMemberPath="Raw" Grid.Row="0" Grid.Column="0" BorderThickness="0" />
<GridSplitter Grid.Column="1" ResizeDirection="Columns" VerticalAlignment="Stretch" Width="3" />
<ListBox ItemsSource="{Binding Users}" DisplayMemberPath="Nick" Visibility="{Binding Type, Converter={StaticResource UserListVisibilityConverter}}" Grid.Row="0" Grid.Column="2" BorderThickness="1,0,0,0" BorderBrush="#FFBBBBBB" MinWidth="130" />
<TextBox Grid.Row="1" Grid.ColumnSpan="3" BorderThickness="0,1,0,0" BorderBrush="#FFBBBBBB" Height="22" />