Skip to content

Commit

Permalink
enable virtualization for SectionView and some of list blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Apr 9, 2024
1 parent 1fa487c commit 8c5cf18
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 191 deletions.
79 changes: 28 additions & 51 deletions MusicX/Controls/Blocks/RecommendedPlaylistsBlockControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,39 @@
</DataTemplate>

<ItemsPanelTemplate x:Key="FullRecommendedPlaylistPanelTemplate">
<ui:VirtualizingWrapPanel Orientation="Vertical" IsItemsHost="True" />
<ui:VirtualizingWrapPanel Orientation="Vertical" IsItemsHost="True"
IsVirtualizing="{TemplateBinding VirtualizingPanel.IsVirtualizing}"
VirtualizationMode="{TemplateBinding VirtualizingPanel.VirtualizationMode}" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="RecommendedPlaylistPanelTemplate">
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" />
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True"
IsVirtualizing="{TemplateBinding VirtualizingPanel.IsVirtualizing}"
VirtualizationMode="{TemplateBinding VirtualizingPanel.VirtualizationMode}" />
</ItemsPanelTemplate>
</ResourceDictionary>
</UserControl.Resources>

<UserControl.Style>
<Style TargetType="{x:Type UserControl}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type collections:IEnumerable}">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.Style>
<Style TargetType="{x:Type ItemsControl}"
BasedOn="{StaticResource {x:Type ItemsControl}}">
<Style.Triggers>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="True">
<Setter Property="ItemsPanel"
Value="{StaticResource FullRecommendedPlaylistPanelTemplate}" />
<Setter Property="ItemTemplate"
Value="{StaticResource FullRecommendedPlaylistTemplate}" />
</DataTrigger>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="False">
<Setter Property="ItemsPanel"
Value="{StaticResource RecommendedPlaylistPanelTemplate}" />
<Setter Property="ItemTemplate" Value="{StaticResource RecommendedPlaylistTemplate}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
</ItemsControl>
</DataTemplate>
</Setter.Value>
</Setter>

<Style.Triggers>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UserControl}">
<hc:ScrollViewer VerticalScrollBarVisibility="Disabled"
CanMouseWheel="False"
HorizontalScrollBarVisibility="Auto"
IsInertiaEnabled="True"
hc:ScrollViewerAttach.AutoHide="True">
<ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</hc:ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
<UserControl.ContentTemplate>
<DataTemplate DataType="{x:Type collections:IEnumerable}">
<ui:ListView ItemsSource="{Binding}">
<ui:ListView.Style>
<Style TargetType="{x:Type ui:ListView}" BasedOn="{StaticResource ItemsListViewStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="True">
<Setter Property="ItemsPanel" Value="{StaticResource FullRecommendedPlaylistPanelTemplate}"/>
<Setter Property="ItemTemplate" Value="{StaticResource FullRecommendedPlaylistTemplate}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="False">
<Setter Property="ItemsPanel" Value="{StaticResource RecommendedPlaylistPanelTemplate}"/>
<Setter Property="ItemTemplate" Value="{StaticResource RecommendedPlaylistTemplate}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
</DataTrigger>
</Style.Triggers>
</Style>
</ui:ListView.Style>
</ui:ListView>
</DataTemplate>
</UserControl.ContentTemplate>

</UserControl>
35 changes: 17 additions & 18 deletions MusicX/Controls/Blocks/RecommsPlaylistBlock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:controls="clr-namespace:MusicX.Controls"
xmlns:models="clr-namespace:MusicX.Core.Models;assembly=MusicX.Core"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Template>
<ControlTemplate TargetType="local:RecommsPlaylistBlock">
<hc:ScrollViewer VerticalScrollBarVisibility="Disabled"
CanMouseWheel="False"
HorizontalScrollBarVisibility="Auto"
IsInertiaEnabled="True"
hc:ScrollViewerAttach.AutoHide="True">
<ItemsControl ItemsSource="{TemplateBinding Playlists}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:Playlist}">
<controls:RecommsPlaylist Margin="0,0,10,0" Playlist="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</hc:ScrollViewer>
<ui:ListView Style="{StaticResource ItemsListViewStyle}" ItemsSource="{TemplateBinding Playlists}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ui:ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True"
IsVirtualizing="{TemplateBinding VirtualizingPanel.IsVirtualizing}"
VirtualizationMode="{TemplateBinding VirtualizingPanel.VirtualizationMode}" />
</ItemsPanelTemplate>
</ui:ListView.ItemsPanel>
<ui:ListView.ItemTemplate>
<DataTemplate DataType="{x:Type models:Playlist}">
<controls:RecommsPlaylist Margin="0,0,10,0" Playlist="{Binding}" />
</DataTemplate>
</ui:ListView.ItemTemplate>
</ui:ListView>
</ControlTemplate>
</UserControl.Template>
</UserControl>
77 changes: 28 additions & 49 deletions MusicX/Controls/ListPlaylists.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:models="clr-namespace:MusicX.Core.Models;assembly=MusicX.Core"
xmlns:collections="clr-namespace:System.Collections;assembly=System.Runtime"
xmlns:hc="https://handyorg.github.io/handycontrol"
Margin="0,0,0,10"
d:DesignHeight="450"
d:DesignWidth="800"
Expand All @@ -17,8 +16,6 @@

<UserControl.Resources>
<ResourceDictionary>


<DataTemplate DataType="{x:Type models:Playlist}" x:Key="FullPlaylistTemplate">
<local:PlaylistControl Margin="0,5" Width="200" Playlist="{Binding}" ShowFull="False" />
</DataTemplate>
Expand All @@ -27,56 +24,38 @@
</DataTemplate>

<ItemsPanelTemplate x:Key="FullPlaylistPanelTemplate">
<ui:VirtualizingWrapPanel Orientation="Vertical" IsItemsHost="True" />
<ui:VirtualizingWrapPanel Orientation="Vertical" IsItemsHost="True"
IsVirtualizing="{TemplateBinding VirtualizingPanel.IsVirtualizing}"
VirtualizationMode="{TemplateBinding VirtualizingPanel.VirtualizationMode}" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="PlaylistPanelTemplate">
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" />
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True"
IsVirtualizing="{TemplateBinding VirtualizingPanel.IsVirtualizing}"
VirtualizationMode="{TemplateBinding VirtualizingPanel.VirtualizationMode}" />
</ItemsPanelTemplate>
</ResourceDictionary>
</UserControl.Resources>

<UserControl.Style>
<Style TargetType="{x:Type UserControl}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type collections:IEnumerable}">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.Style>
<Style TargetType="{x:Type ItemsControl}" BasedOn="{StaticResource {x:Type ItemsControl}}">
<Style.Triggers>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="True">
<Setter Property="ItemsPanel" Value="{StaticResource FullPlaylistPanelTemplate}"/>
<Setter Property="ItemTemplate" Value="{StaticResource FullPlaylistTemplate}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="False">
<Setter Property="ItemsPanel" Value="{StaticResource PlaylistPanelTemplate}"/>
<Setter Property="ItemTemplate" Value="{StaticResource PlaylistTemplate}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
</ItemsControl>
</DataTemplate>
</Setter.Value>
</Setter>

<Style.Triggers>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UserControl}">
<hc:ScrollViewer VerticalScrollBarVisibility="Disabled"
CanMouseWheel="False"
HorizontalScrollBarVisibility="Auto"
IsInertiaEnabled="True"
hc:ScrollViewerAttach.AutoHide="True">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</hc:ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Style>
<UserControl.ContentTemplate>
<DataTemplate DataType="{x:Type collections:IEnumerable}">
<ui:ListView ItemsSource="{Binding}">
<ui:ListView.Style>
<Style TargetType="{x:Type ui:ListView}" BasedOn="{StaticResource ItemsListViewStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="True">
<Setter Property="ItemsPanel" Value="{StaticResource FullPlaylistPanelTemplate}"/>
<Setter Property="ItemTemplate" Value="{StaticResource FullPlaylistTemplate}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ShowFull, ElementName=Control}" Value="False">
<Setter Property="ItemsPanel" Value="{StaticResource PlaylistPanelTemplate}"/>
<Setter Property="ItemTemplate" Value="{StaticResource PlaylistTemplate}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
</DataTrigger>
</Style.Triggers>
</Style>
</ui:ListView.Style>
</ui:ListView>
</DataTemplate>
</UserControl.ContentTemplate>
</UserControl>
24 changes: 8 additions & 16 deletions MusicX/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,16 +598,8 @@
x:Name="QueueGrid"
Grid.Row="1"
Height="0">
<ListBox x:Name="Queue" AllowDrop="True">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
CacheLength="10"
CacheLengthUnit="Item"
Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<ui:ListView x:Name="Queue" Style="{StaticResource ItemsListViewStyle}" AllowDrop="True">
<ui:ListView.ItemTemplate>
<DataTemplate DataType="{x:Type player:PlaylistTrack}">
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -630,14 +622,14 @@
</wpfui:Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="{x:Type ListBoxItem}">
<Setter Property="Focusable" Value="False" />
</ui:ListView.ItemTemplate>
<ui:ListView.ItemContainerStyle>
<Style BasedOn="{StaticResource ItemsListViewItemStyle}" TargetType="{x:Type ListViewItem}">
<EventSetter Event="Drop" Handler="ListBoxItem_OnDrop" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</ui:ListView.ItemContainerStyle>
</ui:ListView>

<wpfui:ProgressRing
x:Name="QueueLoadingRing"
HorizontalAlignment="Center"
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Services/Player/Playlists/TrackExtensions.Vk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public static TrackArtist ToTrackArtist(this MainArtist artist)

public static VkAlbumId ToAlbumId(this Album album)
{
return new(album.Id, album.OwnerId, album.AccessKey, album.Title, album.Cover!.ToString(), album.Thumb?.Photo1200 ?? album.Thumb?.Photo600);
return new(album.Id, album.OwnerId, album.AccessKey, album.Title, album.Cover?.ToString(), album.Thumb?.Photo1200 ?? album.Thumb?.Photo600);
}
}
39 changes: 36 additions & 3 deletions MusicX/Styles/ListViewStyles.xaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol">
<Style x:Key="ItemsListViewItemStyle" TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<ControlTemplate x:Key="ItemsListViewTemplate" TargetType="ui:ListView">
<hc:ScrollViewer
Name="PART_ScrollViewer"
Padding="{TemplateBinding Control.Padding}"
CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}"
Focusable="False"
IsInertiaEnabled="True"
hc:ScrollViewerAttach.AutoHide="True">
<ItemsPresenter />
</hc:ScrollViewer>
</ControlTemplate>

<Style x:Key="ItemsListViewStyle" TargetType="ui:ListView" BasedOn="{StaticResource ListViewStyle}">
<Setter Property="ItemContainerStyle" Value="{StaticResource ItemsListViewItemStyle}" />
<Setter Property="Template" Value="{StaticResource ItemsListViewTemplate}" />

<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="VirtualizingPanel.ScrollUnit" Value="Pixel" />
<Setter Property="VirtualizingPanel.CacheLengthUnit" Value="Item" />
<Setter Property="VirtualizingPanel.CacheLength" Value="2" />
</Style>
</ResourceDictionary>
Loading

0 comments on commit 8c5cf18

Please sign in to comment.