【发布时间】:2014-02-27 17:31:58
【问题描述】:
我有一个 ActiPro ThemedDataGrid(继承自 WPF DataGrid)。 我正在使用网格设置标题 DataTemplate,但它并没有占用所有可用空间。 这是我的数据模板
<DataTemplate x:Key="MyKey" DataType="ViewModels:FieldVM">
<Border BorderThickness="1" BorderBrush="Red">
<Grid VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Label}" DockPanel.Dock="Top" HorizontalAlignment="Center" Grid.Row="0"/>
<Border Grid.Row="1" BorderBrush="Black" BorderThickness="1,0,0,0" Background="{x:Null}" />
<local:MyUserControl Name="units" VerticalAlignment="Bottom" DockPanel.Dock="Bottom" Visibility="Visible" Grid.Row="1"/>
</Grid>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding AvailableUnits}" Value="{x:Null}" >
<Setter Property="Visibility" Value="Collapsed" TargetName="units" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsUnitAware, RelativeSource={RelativeSource AncestorType={x:Type local:UnitConversionGrid}}}" Value="False" >
<Setter Property="Visibility" Value="Collapsed" TargetName="units" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
我希望 Grid 使用所有可用空间,以便它们在 DataGrid 中的所有列中看起来均匀。
如何使 DataTemplate 中的 Grid 占用每列标题中的所有可用空间? 我希望行在所有列中使用相同的高度。 例如,如果第一列中行的高度是 30 和 70,那么我希望所有其他列具有相同的分布。
例子:
---------------------------------
| Row1 with |Row1 | Row1 |
| More Text | | |
|---------------------------------
| Row2 with |Row2 |Row2 |
| More Text | | |
----------------------------------
如何使列中的行占据较大行的高度?
谢谢,
另一个简化的例子:
<Window x:Class="DataGridTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:ActiproSoftware.Windows.Controls.DataGrid;assembly=ActiproSoftware.DataGrid.Contrib.Wpf"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<controls:ThemedDataGrid x:Name="dataGrid" Grid.Row="0" Margin="0,0,10,0" VerticalAlignment="Top" RenderTransformOrigin="-10.556,-1.744" HorizontalAlignment="Right" Width="507" Height="310">
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="50">
<DataGridCheckBoxColumn.Header>
<Grid VerticalAlignment="Stretch" Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridColumnHeader}}, Path=Height}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Width="40" DockPanel.Dock="Top">Value1 Test</TextBlock>
<ComboBox Grid.Row="1" Visibility="Collapsed"/>
</Grid>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
<DataGridCheckBoxColumn>
<DataGridCheckBoxColumn.Header>
<Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Width="50">Value2 Test With Four Lines</TextBlock>
<ComboBox Grid.Row="1"/>
</Grid>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
<DataGridCheckBoxColumn>
<DataGridCheckBoxColumn.Header>
<Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Value3" HorizontalAlignment="Center" DockPanel.Dock="Top" Grid.Row="0"/>
<ComboBox VerticalAlignment="Bottom" Grid.Row="1" Margin="0,1"/>
</Grid>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</controls:ThemedDataGrid>
</Grid>
</Window>
【问题讨论】:
-
可能通过更改或删除共享大小组 A ,将其完全删除,它们将延伸到整个容器。
-
@eranotzap 我已经尝试不使用 SharedSizeGroup 属性但没有成功,Grid 每列的高度不同。
-
@Blam 第二行是 UserControl 不是标准的 WPF 组合框
-
不知道我在哪里说组合框。你有列,行甚至没有排列。可以发张照片吗?
-
您是否尝试将 Grid 替换为 DockPanel?