I am trying to set data template for listbox in code behind using FrameworkElementFactory, I have a checkbox in a data template and i just need to set the font size of the checkbox.
Here is the code.
FrameworkElementFactory Name = new FrameworkElementFactory(typeof(CheckBox));
Name.SetBinding(CheckBox.ContentProperty, new Binding("Content"));
Name.SetBinding(CheckBox.IsCheckedProperty, new Binding("BooleanValue"));
Name.SetValue(CheckBox.FontSizeProperty, 20);
stackpnl.AppendChild(columnName);
In this code I couldn't able to set the FontSizeProperty.
Exception arises showing the message that 20 is not the valid value for font size.
Please correct this code, if something went wrong here. Thanks in advance
FontSize is of a double type so your value must be passed as double to be unboxed properly. Try this:
Name.SetValue(CheckBox.FontSizeProperty, 20D);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With