I have a ListBox
with a UniformGrid
layout and I'm trying to change the "Columns" property, but I don't know the best way of doing that. I tried binding to a property or to create a new layout programatically, but I can't figure it out.
<ListBox x:Name="ImagesList" ItemsSource="{Binding Path=GridImages}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid IsItemsHost="True" Columns="3" VerticalAlignment="Top" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
I'm trying to change between 1 and 3 columns, when the user click on two buttons. I've tried binding with Columns="{Binding Path=MyColumnCount}"
, but it never changes, and tried to set a x:Name
and access from my code, without success. I also tried to instantiate a new UniformGrid
, but I've read that I need a factory for that, so I can't set a different Columns
value.