This is similar to my previous question, but that solution did not solve this problem.
fontSizeProperty is not being recognized when I move a method from my Silverlight MainPage code behind (which worked) to a new class in a silverlight library
using System.Windows.Controls;
namespace MyNameSpace
{
public static class DataGridBuilder
{
private static Style BuildHeaderStyle(string tooltip)
{
Style newGridHeaderStyle = new Style(typeof(DataGridColumnHeader));
newGridHeaderStyle.Setters.Add(new Setter { Property = FontSizeProperty, Value = 9.0 });
newGridHeaderStyle.Setters.Add(new Setter { Property = FontWeightProperty, Value = FontWeights.Bold });
return newGridHeaderStyle;
}
}
}
NOTE: Per MSDN for FontSizeProperty, I do include System.Windows reference, and “using System.Windows.Control”
Based on answers below, I changed “Property = FontSizeProperty” to “Property=DataGridColumnHeader.FontSizeProperty” etc., like this:
private static Style BuildHeaderStyle(string tooltip)
{
FontWeight fw = FontWeights.Bold;
Style newGridHeaderStyle = new Style(typeof(DataGridColumnHeader));
newGridHeaderStyle.Setters.Add(new Setter { Property = DataGridColumnHeader.FontSizeProperty, Value = 9.0 });
newGridHeaderStyle.Setters.Add(new Setter { Property = DataGridColumnHeader.FontWeightProperty, Value = FontWeights.Bold });
newGridHeaderStyle.Setters.Add(new Setter { Property = DataGridColumnHeader.ContentTemplateProperty, Value = CreateDataGridHeaderTemplate(tooltip) });
return newGridHeaderStyle;
}
I believe you want
Control.FontSizePropertyandControl.FontWeightPropertyinstead.Your
MainPageis a user control, which hasControlas a superclass and hence inherits the above two dependency properties. Your static class isn’t a subclass ofControlso it doesn’t inherit these dependency properties.