Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
785
Inheriting style bindings
posted

Hi,

   In the SL3 grid that I use, I can bind the FontSize, FontFamily, FontStyle, FontWeight and the values are nicely propagated down to the cell.

   In the XamWebGrid the values aren't propagated. I could set the values as StaticResources and then bind them in each TextBlock but that's quite a lot of work and bother. I see there's a FontSize property in the CellControl style. Is it possible to tell it to get its value from its parent (the XamWebGrid)?

 

Cheers.

  • 785
    Suggested Answer
    posted

    I found a way of achieving this by hooking up on the Loaded event and doing the following:

            private void OnLoaded(object sender, RoutedEventArgs e)
            {
                var cellControlStyle = new Style(typeof(CellControl));
                if (CellStyle != null)
                {
                    cellControlStyle.BasedOn = CellStyle;
                }

                cellControlStyle.Setters.Add(new Setter(CellControl.FontFamilyProperty, FontFamily));
                cellControlStyle.Setters.Add(new Setter(CellControl.FontSizeProperty, FontSize));
                cellControlStyle.Setters.Add(new Setter(CellControl.FontStyleProperty, FontStyle));
                cellControlStyle.Setters.Add(new Setter(CellControl.FontWeightProperty, FontWeight));

                CellStyle = cellControlStyle;
            }

     

    Works OK.