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
5520
Cell Style problem
posted

hi,

i am having a problem with the cell style.

 i have attached a sample. the scenario is:

 

  • select cells
  • check the checkbox Bold => the selected cells are bold
  • check the checkbox Italic => the selected cells are italic but not bold anymore

 

while if you do the opposite

Italic then bold it works fine.

what i want is to be able to control the cells just like MS Excel. when i check bold make the selected cell bold. when i check italic make cell italic (if the cell already was bold keep it bold and italic) and so on.

 

Parents
  • 40030
    Verified Answer
    Offline posted

    Hi, 

    You should use the BasedOn property of the style instead, of trying to copy them.  As Styles are tricky objects, which don't always return the actual property state once they're used:

    So, in your code instead of:
     Style s = new System.Windows.Style(typeof(CellControl));

                    if (c.Style != null)

                    {

                        s = M_CopyStyle(c.Style, new DependencyProperty[] { FontWeightProperty });

                    }

    use:

    Style s = new System.Windows.Style(typeof(CellControl));

                    if (c.Style != null)

                    {

                        s.BasedOn = c.Style;

                        //s = M_CopyStyle(c.Style, new DependencyProperty[] { FontWeightProperty });

                    }

    -Hope this helps, 

    -SteveZ

Reply Children