I want to create a basic user control with a style programmatically.
In this style I want to add a Grid
(no problem), but I can\'t add column definitions to thi
FrameworkElementFactory has some custom logic for handling the ColumnDefinitions and RowDefinitions in a Grid. For those values, you treat them like children in the factory tree, for example:
FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid));
var column1 = new FrameworkElementFactory(typeof(ColumnDefinition));
column1.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Auto));
var column2 = new FrameworkElementFactory(typeof(ColumnDefinition));
column2.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));
gridFactory.AppendChild(column1);
gridFactory.AppendChild(column2);