我想为 WPF 中的多个列做 Header DataGrid
。我尝试使用 Header 模板,但它会显示一列的 Header。
在我尝试过的 XAML 下面:
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn>
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock>Column 1</TextBlock>
<TextBlock>xyz</TextBlock>
</StackPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
<DataGridTextColumn Header="Header" />
</DataGrid.Columns>
</DataGrid>
我还附上了我的预期结果屏幕截图:
<Grid Width="Auto">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<toolkit:DataGrid x:Name="problemsList"
MinHeight="205"
MaxHeight="205"
Margin="3"
VerticalAlignment="Top"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="True"
CanUserResizeRows="False"
ColumnHeaderStyle="{StaticResource GridColumnHeaderStyle}"
HorizontalScrollBarVisibility="Visible"
ItemsSource="{Binding FisapCorrections}"
MouseLeftButtonUp="problemsList_MouseLeftButtonUp"
SelectionMode="Single"
Sorting="problemsList_Sorting"
VerticalScrollBarVisibility="Auto">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTemplateColumn MinWidth="50"
CellTemplate="{StaticResource RowSelected}"
Header="Select" />
<toolkit:DataGridTextColumn MinWidth="88"
Binding="{Binding StudentName}"
Header="Student Name"
IsReadOnly="True" />
<toolkit:DataGridTextColumn x:Name="dgtcSSN"
MinWidth="50"
Binding="{Binding SSN}"
Header="SSN"
IsReadOnly="True" />
<toolkit:DataGridTextColumn x:Name="dgtcStuNum"
MinWidth="50"
Binding="{Binding StuNum}"
Header="StuNum"
IsReadOnly="True" />
<toolkit:DataGridTextColumn MinWidth="80"
Binding="{Binding Campus}"
Header="Campus"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="50"
MinWidth="50"
Binding="{Binding BadModel,
Converter={StaticResource ToEmptyStringConverter}}"
Header="BadModel"
HeaderTemplate="{StaticResource DepModelHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="72"
MinWidth="72"
Binding="{Binding BadPellEnrollStatus,
Converter={StaticResource ToEmptyStringConverter}}"
CanUserReorder="False"
Header="BadPellEnrollStatus"
HeaderTemplate="{StaticResource EnrollStatusHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="75"
MinWidth="75"
Binding="{Binding DupePell,
Converter={StaticResource ToEmptyStringConverter}}"
Header="DupePell"
HeaderTemplate="{StaticResource DupStudentPellHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="80"
MinWidth="80"
Binding="{Binding BadTransactionId,
Converter={StaticResource ToEmptyStringConverter}}"
Header="BadTransactionId"
HeaderTemplate="{StaticResource InvTransactionIDHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="40"
MinWidth="40"
Binding="{Binding HasNoISIR,
Converter={StaticResource ToEmptyStringConverter}}"
Header="HasNoISIR"
HeaderTemplate="{StaticResource NoISIRHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="75"
MinWidth="75"
Binding="{Binding GradWithSEOG,
Converter={StaticResource ToEmptyStringConverter}}"
Header="GradWithSEOG"
HeaderTemplate="{StaticResource NotEligxSEOGHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="100"
MinWidth="100"
Binding="{Binding GradIsDependent,
Converter={StaticResource ToEmptyStringConverter}}"
Header="GradIsDependent"
HeaderTemplate="{StaticResource GradWithDepModelHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="60"
MinWidth="60"
Binding="{Binding NoClasses,
Converter={StaticResource ToEmptyStringConverter}}"
Header="NoClasses"
HeaderTemplate="{StaticResource NoClassesHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="65"
MinWidth="65"
Binding="{Binding Ineligible}"
Header="Ineligible"
HeaderTemplate="{StaticResource SchoolStatusHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTemplateColumn IsReadOnly="True">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="Main Header Text" Grid.columnSpan="3" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="Text 1" grid.Column="0" grid.Row="1"/>
<TextBlock Text="Text 2" grid.Column="1" grid.Row="1"/>
<TextBlock Text="Text 3" grid.Column="2" grid.Row="1"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
<toolkit:DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Missing from FISAP Summary Part II Section F"
TextWrapping="Wrap"
Width="200"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.HeaderTemplate>
</toolkit:DataGridTemplateColumn>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
<CmcControls:WaitingControl x:Name="waitingControlOnGrid"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
我想在最后一个网格中添加预期结果