我在Windows应用商店应用项目中使用SfDataGrid数据网格控件,我能够将我的服务器样式应用于不同的行,但特别是有一行我想要具有不同的样式。 这是我到目前为止所做的。
<Page.Resources>
<Style x:Key="customCellStyle" TargetType="syncfusion:GridCell">
<Setter Property="BorderBrush" Value="#FF7fd0de" />
<Setter Property="BorderThickness" Value="1,0,0,1" />
<Setter Property="Padding" Value="0,0,0,0" />
<Setter Property="FontFamily" Value=" Segoe UI" />
<Setter Property="Foreground" Value="#FF2A2A2A" />
<Setter Property="FontSize" Value="14" />
<!--<Setter Property="Height" Value="59" />-->
</Style>
<Style x:Key="rowStyle" TargetType="syncfusion:VirtualizingCellsControl">
<Setter Property="Background" Value="WhiteSmoke" />
</Style>
<Style x:Key="altRowStyle" TargetType="syncfusion:VirtualizingCellsControl">
<Setter Property="Background" Value="White" />
</Style>
</Page.Resources>
<Grid x:Name="rootGrid" Style="{StaticResource RootGridStyle}" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<syncfusion:SfDataGrid Grid.Row="1" x:Name="datagrid" Width="1366"
AllowResizingColumns="True"
AutoGenerateColumns="True"
CellStyle="{StaticResource customCellStyle}"
ColumnSizer="Star"
RowHeight="65"
AlternatingRowStyle="{StaticResource altRowStyle}"
RowStyle="{StaticResource rowStyle}" />
<ProgressRing Grid.Row="1" IsActive="{Binding IsLoading}" />
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonReverseStyle}"/>
</Grid>
如何将特定样式应用于其中一行,请说第3行。
答案 0 :(得分:1)
通过使用RowStyleSelector,您可以应用特定行的样式。 请参考此链接: http://help.syncfusion.com/wpf/sfdatagrid/conditional-styling#rows
public class CustomRowStyleSelector : StyleSelector
{
protected override Style SelectStyleCore(object item, Windows.UI.Xaml.DependencyObject container)
{
var row = item as DataRowBase;
if (row.RowIndex == 3)
return App.Current.Resources["rowStyle"] as Style;
return base.SelectStyleCore(item, container);
}
}
<syncfusion:SfDataGrid x:Name="sfdatagrid" Grid.Row="0"
AutoGenerateColumns="True"
ItemsSource="{Binding Path=Products}"
RowStyleSelector="{StaticResource rowStyleSelector}"/>