I have a markup. ListBox are generated, they have a little more elements than can fit on the screen. Scrolling does not work for some reason.

<ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <Label Content="{Binding Day}"/> <ListBox ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <local:iDayControl/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 
  • one
    How to create a short, complete and reliable example . Make an example complete and independent of your controls. - Athari
  • one
    it is not very clear why you use another collection (listbox) as a data template for a collection item (itemscontrol). - Fony Fazoulyanov
  • @FonyFazoulyanov is the structure of the application, I have a collection from the collections that I need to display. - bodynar

2 answers 2

All example code:

 <Window x:Class="WpfApplication8.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication8" mc:Ignorable="d" d:DataContext="{d:DesignInstance local:MainWindow}" Title="MainWindow" Height="350" Width="525"> <Grid> <ItemsControl ItemsSource="{Binding CardList}" BorderBrush="#FFCB2F2F" BorderThickness="2"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"> </StackPanel> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ScrollViewer> <StackPanel> <Label Content="{Binding Name}" /> <ListBox ItemsSource="{Binding WorksList}"> </ListBox> </StackPanel> </ScrollViewer> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> 

CodeBehind for MainWindow:

 using System.Collections.Generic; using System.Windows; namespace WpfApplication8 { public partial class MainWindow : Window { public List<WorkCard> CardList { get; set; } public MainWindow() { InitializeComponent(); List<string> tmp = new List<string>(){"1", "2", "3", "4", "5"}; List<string> tmp1 = new List<string>() { "1", "2", "3", "4", "5", "1", "2", "3", "4", "5" }; CardList = new List<WorkCard>() { new WorkCard("First", tmp), new WorkCard("Second", tmp), new WorkCard("Third", tmp), new WorkCard("Fourth", tmp1), new WorkCard("Fifth", tmp) }; DataContext = this; } } public class WorkCard { public string Name { get; set; } public List<string> WorksList { get; set; } public WorkCard (string name, List<string> list) { Name = name; WorksList = list; } } } 
  • ListView I can't use it because I need to select items within the visual collection (ListBox, for example) - bodynar
  • so in ListView there is also a SelectedItem property. - Fony Fazoulyanov
  • Suppose I changed the ListBox to a ListView, the scroll did not appear (both physically and visually) - bodynar
  • Change ItemsControl to ListView and it will work - Fony Fazoulyanov
  • one
    @bodynar and if you still enclose the stackpanel in the datatemplate in the ScrollViewer, then you will have a slider for each individual list. - Fony Fazoulyanov

The issue is resolved.

Added ScrollViewer, as advised by @Fony Fazoulyanov around the item holding the ItemsControl.

 <TabControl.ContentTemplate> <DataTemplate> <ScrollViewer> <LocalContr:iWeekControl/> </ScrollViewer> </DataTemplate> </TabControl.ContentTemplate>