我有一个ActiPro主题化的DataGrid(继承自WPF DataGrid)。 我正在使用Grid设置标题DataTemplate,但它没有占用所有可用空间。 这是我的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>
我希望网格使用所有可用空间,以便在DataGrid的所有列中看起来均匀。
如何使DataTemplate中的网格占用每个列标题内的所有可用空间? 我希望所有列中的行使用相同的高度。 例如,如果第一列的行高为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>