我有一个
WPF
应用程序。我用
Mahapps.Metro
是的。主窗口上的主控件是
DataGrid
.我希望它是一个表,但我希望列标题和每行的第一个单元格有一个稍微不同的样式。目前看来:
所以列标题没问题。但现在我希望每行的第一个单元格是特殊的,比如列标题(更大的字体,粗体,可能是垂直边框,比如水平边框)。有办法吗?(记住,我在代码中添加每一列和每一行,而不是在xaml中)。
目前,我的xaml代码如下所示:
<Controls:MetroWindow x:Class="StateMachines.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="Maszyny Mealy'ego i Moora"
Height="450"
Width="800">
<Controls:MetroWindow.RightWindowCommands>
<Controls:WindowCommands>
<Button Content="settings" />
<Button>
<StackPanel Orientation="Horizontal">
<Rectangle Width="20"
Height="20"
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_cupcake}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Margin="4 0 0 0"
VerticalAlignment="Center"
Text="do something" />
</StackPanel>
</Button>
</Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>
<DataGrid x:Name="DataGridLogic" Margin="318,59,0,136" Width="452" RenderTransformOrigin="0.657,1.249"
ItemsSource="{Binding Path=Logic.DefaultView}" ColumnWidth="*" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserAddRows="False" CanUserSortColumns="False" CanUserResizeRows="False">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MetroDataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.RowHeaderStyle>
<Style TargetType="{x:Type DataGridRowHeader}" BasedOn="{StaticResource MetroDataGridRowHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.RowHeaderStyle>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource MetroDataGridCell}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGrid.CellStyle>
</DataGrid>
</Controls:MetroWindow>