我有一个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>
答案 0 :(得分:1)
我将使用基于displayindex的样式触发器。
var pretest = function () {
var MAX_NUM = 250.0;
var prebase = function (NEW_NUM) {
this.NEW_NUM = NEW_NUM ? NEW_NUM : true;
};
prebase.prototype.testmenow = function () {
return this.NEW_NUM;
};
return prebase;
};
var b = new pretest(111);
console.log(b.testmenow());