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

GridStackedHeaderCell Style binding properties

I have a grid with some StackedHeaders. Everything is created on code behind.  using your how- to (http://www.syncfusion.com/kb/2509/how-to-insert-combobox-in-stackedheader) I have a style in app.xaml:

<Style x:Key="stackedHeaderCell"
            <Setter Property="BorderThickness"
                    Value="0,0,3,1" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Center" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="Padding"
                    Value="0,0,0,0" />
            <Setter Property="IsTabStop"
                    Value="False" />
            <Setter Property="FontWeight"
                    Value="Bold" />

And i use this code:

            gridView.CellRenderers.Add("StackedHeader", new GridStackedHeaderCellRendererExt());

and  the new class is:

public class GridStackedHeaderCellRendererExt : GridStackedHeaderCellRenderer
        // override the OnInitializeEditElement
        public override void OnInitializeEditElement(
                                            Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex rowColumnIndex,
                                            GridStackedHeaderCellControl uiElement, GridColumn column, object dataContext)
            var colum = (dataContext as StackedColumn);
            // Apply the custom style for Customer Details StackedHeader
            var style = App.Current.Resources["stackedHeaderCell"] as Style;
            uiElement.Style = style;

            base.OnInitializeEditElement(rowColumnIndex, uiElement, column, dataContext);

I have multiple pages with viewmodels and i want to bind some properties of the style  for each page i have eg background and foreground in order to change themes . so i created a new style like this for every page i have:

<Style x:Key="stackedHeaderCellPage1"
                   BasedOn="{StaticResource stackedHeaderCell}">
            <Setter Property="Background"
                    Value="{Binding DataContext.StackedHeaderRowBackgroundColor}" />
            <Setter Property="Foreground"
                    Value="{Binding DataContext.StackedHeaderRowForegroundColor}" />         

I edited the code in OnInitializeEditElement to this with no result:

WinStart window = (WinStart)Application.Current.MainWindow;
Style newStyle = (window.MainViewPage.Content as PageMainView).Resources["stackedHeaderCellMainView"] as Style;
uiElement.Style = newStyle ;

How can i have bind properties in my style?

I'm using the 12.1450.0.43 version

Thank you


1 Reply

JS Jayapradha S Syncfusion Team March 11, 2015 12:48 PM UTC

Hi George,

Thank you for using Syncfusion products.

We have analyzed your query and found that you have tried to change the background and foreground based on property in ViewModel. For StackedHeaderCellControl, DataContext won’t be a ViewModel class, hence the binding is not working for you. You can change the binding as shown in below code snippet,

Code Snippet:

      <Style x:Key="stackedHeaderCellPage1"


                   BasedOn="{StaticResource stackedHeaderCell}">

            <Setter Property="Background"

                    Value="{Binding DataContext.StackedHeaderRowBackgroundColor,RelativeSource={RelativeSource AncestorType=syncfusion:SfDataGrid}}" />

            <Setter Property="Foreground"

                    Value="{Binding DataContext.StackedHeaderRowForegroundColor,RelativeSource={RelativeSource AncestorType=syncfusion:SfDataGrid}}" />


Please let us know if you require any further assistance.

With Regards,


Live Chat Icon For mobile
Up arrow icon