Originally I wanted to make listview dependant on window height parameter, but to be honest I find this solution impractical, believing it can be done better.
So, here is an object of my interest:
<StackPanel>
<TextBlock Text="{Binding LessonTitle}" Foreground="Black" HorizontalAlignment="Center" Margin="0,10,0,0" FontSize="36" Background="DimGray"></TextBlock>
<Grid Height="Auto" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<ListView x:Name="LV2" Background="DimGray"
BorderBrush="Transparent"
ItemsSource="{Binding Lessons}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SizeChanged="LV2_SizeChanged">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Height="1000"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Hidden">
<TextBlock Width="Auto" FontSize="24" Foreground="Black" TextWrapping="Wrap">
<Run Text="{Binding LessonText}"/>
</TextBlock>
<Image Source="{Binding LessonImage}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</StackPanel>
My listview and remnants of several attempts to make it scrollable (also also resizable with the window), and by scrollable I mean to make an entire list scroll smoothly, instead of by each element, but I have no clue how to achieve it.
I've already tried changing stackpanels to dockpanels/grids and vice versa, different scrollviwer placements, but none of them work. At best what I could've achieved so far was either scrolling listview's first item or scrolling item by item.
UPDATE:
So far I seem to have achieved the desired result:
<StackPanel>
<TextBlock Text="{Binding LessonTitle}" Foreground="Black" HorizontalAlignment="Center" Margin="0,10,0,0" FontSize="36" Background="DimGray"></TextBlock>
<Grid Height="Auto">
<ScrollViewer x:Name="SV" VerticalScrollBarVisibility="Visible" SizeChanged="SV_SizeChanged">
<ListView x:Name="LV2" Background="DimGray"
BorderBrush="Transparent"
ItemsSource="{Binding Lessons}"
Width="Auto" Height="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="Auto">
<TextBlock Width="Auto" FontSize="24" Foreground="Black" TextWrapping="Wrap">
<Run Text="{Binding LessonText}"/>
</TextBlock>
<Image Source="{Binding LessonImage}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
</StackPanel>
This is how I did it in XAML, I've put an entire listview into a scrollviewer and made the size dependant on the window size throught this function:
private void SV_SizeChanged(object sender, SizeChangedEventArgs e)
{
SV.Height = HeightModel.Instance.Height - 100;
SV.Width = HeightModel.Instance.Width - 120;
}
I also added width and height ot the listview.
However the size updates only upon changing the view and not in real time. So now I need help to make it actually responsive, either by making this function work in real time or purely throught XAML.
The other problem is that for some reason I cannot scroll the listview with mouse scholl, but only with mouse click, and I am completely confused why it happened to work like this.
ListBox has these properties by default. just define the size of the visible area and everything extending beyond that comes scrollable. You may want to separate the items to their own item slots instead of a stackpanel that extends far beyond the dimensions of its contents as well. Here is an example:
Note that if Lessons is a class and has properties in it then the box will automatically add them when defined as the ItemssSource. Also Some controls won't allow you to manipulate the items beyond the scope of its privileges if it is inheriting from an itemssource, instead manipulate the source itself to change the items.
If you need to populate the list with a larger quantity of items the easiest way would be in the .cs / vb codebehind. The C# would be something like:
If you require multiple types of parent controls add an if else loop to check the type and a foreach loop to handle the respective type
XAML
Codebehind
alternate codebehind