Reputation: 39
I have a ListBox whose ItemsSource is bound to a collection of Objects. My button content is bound to MyObject property "Name". When displaying on the UI, i want to wrap my buttons in such away that when they reach the end of the app i start displaying them in another new line of buttons . Apparently i am only displaying the first few buttons and the rest is cut off. The Wrap Panel which i was counting on seems to have been phased out.
My view (xaml):
<ListBox Grid.Row="1" ItemsSource="{Binding Objects}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Button Margin="2" Content="{Binding Name}" Width="200" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My ViewModel:
public ObservableCollection<MyObject> Objects { get; set; }
public MainViewModel()
{
Objects = new ObservableCollection<MyObject>();
Add();
}
private void Add()
{
for (int i = 0; i < 15; i++)
{
Objects.Add(new MyObject() { Name = i});
}
}
public class MyObject
{
public int Name { get; set; }
}
ANY IDEAS !! THANKS
Upvotes: 3
Views: 2031
Reputation: 3603
You could use the wrappanel from the toolkit http://go.microsoft.com/fwlink/p/?LinkId=267555
Upvotes: 2
Reputation: 6570
You can use an ItemsWrapGrid for that scenario, used in a similar way:
<ListView ...>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid .../>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Upvotes: 6