Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting font size property for FrameworkElementFactory

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

like image 242
Hafiz H Avatar asked Jan 31 '26 15:01

Hafiz H


1 Answers

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);
like image 189
dkozl Avatar answered Feb 02 '26 05:02

dkozl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!