We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Does not apply style from App.xaml

Hi,

I have my style define in App.xaml like folowing

 <Style TargetType="Label" Class="HeaderLabel">
        <Setter Property="TextColor" Value="{StaticResource LabelDarkColor}"></Setter>
        <Setter Property="FontSize" Value="Large"></Setter>
        <Setter Property="FontFamily">
          <OnPlatform x:TypeArguments="x:String">
            <OnPlatform.Android>GeosansLight.ttf#GeosansLight</OnPlatform.Android>
            <OnPlatform.iOS>GeosansLight.ttf</OnPlatform.iOS>
          </OnPlatform>
        </Setter>
 </Style>

but it is not getting applied to any to lable placed with in SfDataGrid.

Regards,
Mahesh



3 Replies

AN Ashok N Syncfusion Team November 10, 2016 12:35 PM UTC

Hi Maheshkumar, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and you can customize the Grid style by customizing GridCell style and bind the style into GridColumn.CellStyle property as in the below code example. 
App.xaml: 
<Application.Resources> 
  <ResourceDictionary> 
    <Style TargetType="sfgrid:GridCell" x:Key="gridCellStyle"> 
      <Setter Property="BackgroundColor" Value="Green"></Setter> 
      <Setter Property="Foreground" Value="Red"></Setter> 
    </Style> 
  </ResourceDictionary> 
</Application.Resources> 
                        
ContentPage.xaml 
<sfgrid:SfDataGrid.Columns x:TypeArguments="sfgrid:Columns"> 
  <sfgrid:GridTextColumn MappingName="OrderID" CellStyle="{StaticResource gridCellStyle}"> 
  </sfgrid:GridTextColumn> 
</sfgrid:SfDataGrid.Columns> 


Also customize the style by overriding DataGridStyle and assigning it to the SfDataGrid.GridStyle property. Please refer the below UG link to get more information about SfDataGrid.GridStyle. 

Regards, 
Ashok 



MA Maheshkumar November 11, 2016 11:42 PM UTC

Hi Ashok, 

That's not what I want. Please see below code, I have a template column

<syncfusion:GridTemplateColumn MappingName="id" >
              <syncfusion:GridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Label Text="{Binding NoticeDate, StringFormat='{0:dd/MM/yyyy}'}}"  Margin="10, 0, 0, 0"  StyleClass="HeaderLabel"/>
                </DataTemplate>
              </syncfusion:GridTemplateColumn.CellTemplate>
</syncfusion:GridTemplateColumn>

 
See above StyleClass applied to lable is not getting applied.

Regards,
Mahesh


AN Ashok N Syncfusion Team November 14, 2016 11:56 AM UTC

Hi MaheshKumar, 

 
We have checked your query and you can achieve your requirement by binding Style to Label, as in the below code example  
App.Xaml: 
<Application.Resources> 
  <ResourceDictionary> 
   <Style x:Key="labelStyle" TargetType="Label" > 
    <Setter Property="TextColor" Value="Red"></Setter> 
    <Setter Property="FontSize" Value="Large"></Setter> 
   </Style> 
  </ResourceDictionary> 
</Application.Resources>
 

 
Main page: 
<sfgrid:GridTemplateColumn MappingName="ShippingDate" > 
  <sfgrid:GridTemplateColumn.CellTemplate> 
   <DataTemplate> 
    <Label Text="{Binding ShippingDate, StringFormat='{0:dd/MM/yyyy}'}}" Style="{StaticResource labelStyle}"/> 
   </DataTemplate> 
  </sfgrid:GridTemplateColumn.CellTemplate> 
</sfgrid:GridTemplateColumn>
 

 
Regards, 
Ashok 


Loader.
Up arrow icon