Im making a simple LOB application that loads data from an XML file and displays it in a list with a few buttons for editing.
In my first attempt, everything was in order, except that the list scrolled down in one long column. I would prefer the data to be wrapped so that at the bottom of the window it launches a second column, etc. - if you resize the window, the data should resize accordingly.
First, I just put the ListBox inside the ScrollViewer. It didn't make any difference.
Then I added a WrapPanel to the ItemTemplate. At this point, I got a long row horizontally, but it was never moved to the second row, despite the fact that my ScrollViewer.HorizontalScrollbar = parameter is disabled.
I searched the Internet for various blogs and forums, but I donβt see the difference between the sentences and my code (see below). Any advice would be highly appreciated.
<Window x:Class="MyApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="My App" Height="300" Width="400" FocusManager.FocusedElement="{Binding ElementName=eventsList}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <ScrollViewer Grid.Row="0" Grid.Column="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"> <ListBox Name="eventsList"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> </ScrollViewer> <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="Collapsed"> <Button Name="action1Button" /> <Button Name="action2Button" /> <Button Name="action3Button" /> </StackPanel> </Grid> </Window>
Saqib source share