WPF XAML WrapPanel ListBox Items in String

I have to ask for help, although I cannot figure it out myself. I am working on a WPF-XAML desktop application in which a GUI is dynamically generated.

My request is for styling a WrapPanel with ListBox elements.

Please find the code snippet from my usercontrol (.xaml):

<DockPanel x:Name="xResultPanel"> <ListView x:Name="bResultPanel" ItemsSource="{Binding ResultList, UpdateSourceTrigger=PropertyChanged}"> <ListView.ItemTemplate> <DataTemplate> <Expander Header="{Binding GroupName}" Style="{DynamicResource FeatureExpander2}"> <WrapPanel ItemWidth="140" Orientation="Horizontal"> <ListBox x:Name="ListOfTiles" ItemsSource="{Binding VideoSamples}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Width="120" Margin="10" HorizontalAlignment="Left"> <Image /> <TextBlock /> </StackPanel </DataTemplate> </ListBox.ItemTemplate> </ListBox> </WrapPanel> </Expander> </DataTemplate> </ListView.ItemTemplate> </ListView> </DockPanel> 

Above the code returns ListBox items that are not represented in a row, but each item in a new row. I tried setting MinWidth, Width, etc. For WrapPanel and ListBox, but with no result.

Thanks in advance for all the related tips on how to get WrapPanel to fill it horizontally.

+6
source share
1 answer

The problem is that your WrapPanel has only one child: ListBox . This means that the layout is done using the ItemsPanel ListBox template.

Try this instead:

  <Expander Header="{Binding GroupName}" Style="{DynamicResource FeatureExpander2}"> <ListBox x:Name="ListOfTiles" ItemsSource="{Binding VideoSamples}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Width="120" Margin="10" HorizontalAlignment="Left"> <Image /> <TextBlock /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> </Expander> 
+11
source

Source: https://habr.com/ru/post/946403/


All Articles