|
<Application.Resources>
<ResourceDictionary>
<Color x:Key="Primary">Red</Color>
</ResourceDictionary>
</Application.Resources>
<ContentPage.Resources>
<ResourceDictionary>
<local:GridStyleConverter x:Key="StyleConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<sfgrid:SfDataGrid.Columns>
<sfgrid:GridTextColumn
MappingName="OrderID">
<sfgrid:GridTextColumn.CellStyle>
<Style TargetType="sfgrid:GridCell">
<Setter Property="Foreground" Value="{Binding ., Converter={StaticResource StyleConverter}, ConverterParameter={DynamicResource Primary}}" />
</Style>
</sfgrid:GridTextColumn.CellStyle>
</sfgrid:GridTextColumn>
</sfgrid:SfDataGrid.Columns>
public class GridStyleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(value != null)
{
var resource = parameter as Xamarin.Forms.Internals.DynamicResource;
return Application.Current.Resources[resource.Key];
}
return Color.Black;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Color.Black;
}
} |