1

How can I set the Rows and Columns of that UniformGrid in c# code behind?

   <ListBox x:Name="galerielb"   Margin="10,0,0,10"  
         ItemContainerStyle="{StaticResource SimpleListBoxItem}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Rows="10" Columns="6"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
mm8
  • 163,881
  • 10
  • 57
  • 88
daniel
  • 34,281
  • 39
  • 104
  • 158

1 Answers1

1

Since it's just a template, you could create a new one and set the ItemsPanel property directly:

FrameworkElementFactory ug = new FrameworkElementFactory(UniformGrid);
ug.SetValue(UniformGrid.RowsProperty, 10);
ug.SetValue(UniformGrid.ColumnsProperty, 6);
galerielb.ItemsPanel = new ItemsPanelTemplate(ug);
mm8
  • 163,881
  • 10
  • 57
  • 88