hi,
i am having a problem with the cell style.
i have attached a sample. the scenario is:
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.
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));
s.BasedOn = c.Style;
//s = M_CopyStyle(c.Style, new DependencyProperty[] { FontWeightProperty });
-Hope this helps,
-SteveZ
Thanks :)
is there a way to make it underline?
no what i want to do is to get the current style of the cell.
if it's bold or italic. not get it back to it's original.
i kind of found a solution
private bool M_CheckActiveCellProperty(DependencyProperty dp,int hashValue)
if(XamMainGrid.ActiveCell!=null && XamMainGrid.ActiveCell.Style!=null)
Style s = XamMainGrid.ActiveCell.Style;
while (s.BasedOn != null && ((Setter)s.Setters[0]).Property != dp)
s = s.BasedOn;
if (((Setter)s.Setters[0]).Property == dp)
return (int)((Setter)s.Setters[0]).Value.GetHashCode() == hashValue;
return false;
this way i will check if the active cell is bold or italic ..
Are you asking how to reset the style back to its original?
if so, then just set the property to null.
Hi again,
once i set the style for a cell, how can i get it back to know the current style? (Bold/Italic...)
To underline a specific cell, it needs to be a TextBlock, as thats a TextBlock specific property..TextDecoration
Since CellControl's are just ContentControls, you're not going to be able to set that property on your individual cells.