Cómo establecer ItemsPanelTemplate en una cuadrícula creada dinámicamente en el código detrás de
Tengo estoUserControl
definido enXAML
y me gustaría establecer elItemsPanelTemplate
dinámicamente en mi código detrás de la clase (no en elXAML
como en el ejemplo):
<UserControl>
<ItemsControl x:Name="Items">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid> <!-- I want to add this Grid definition in code behind -->
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</UserControl>
Intenté algo como
this.Items.ItemsPanel.Template = new Grid();
pero falló miserablemente. ¿Alguna ayuda
Antecedentes Solo sé el número de columnas y filas de cuadrícula en tiempo de ejecución.