using System.Threading.Tasks;
using StrixMusic.Sdk.ViewModels;
using StrixMusic.Sdk.WinUI.Controls.Collections.Abstract;
using StrixMusic.Sdk.WinUI.Controls.Items;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace StrixMusic.Sdk.WinUI.Controls.Collections
{
///
/// A templated for displaying an .
///
///
/// This class temporarily only displays s.
///
public partial class PlaylistCollection : CollectionControl
{
///
/// Initializes a new instance of the class.
///
public PlaylistCollection()
{
this.DefaultStyleKey = typeof(PlaylistCollection);
}
///
/// Backing dependency property for .
///
public IPlaylistCollectionViewModel Collection
{
get { return (IPlaylistCollectionViewModel)GetValue(CollectionProperty); }
set { SetValue(CollectionProperty, value); }
}
///
/// Dependency property for .
///
public static readonly DependencyProperty CollectionProperty =
DependencyProperty.Register(nameof(Collection), typeof(IPlaylistCollectionViewModel), typeof(PlaylistCollection), new PropertyMetadata(0));
///
protected override void OnApplyTemplate()
{
// OnApplyTemplate is often a more appropriate point to deal with
// adjustments to the template-created visual tree than is the Loaded event.
// The Loaded event might occur before the template is applied,
// and the visual tree might be incomplete as of Loaded.
base.OnApplyTemplate();
AttachHandlers();
}
///
protected override async Task LoadMore()
{
if (!Collection.PopulateMorePlaylistsCommand.IsRunning)
await Collection.PopulateMorePlaylistsCommand.ExecuteAsync(25);
}
///
protected override void CheckAndToggleEmpty()
{
if (!Collection.PopulateMorePlaylistsCommand.IsRunning &&
Collection.TotalPlaylistItemsCount == 0)
SetEmptyVisibility(Visibility.Visible);
}
private void AttachHandlers()
{
Unloaded += PlaylistCollection_Unloaded;
}
private void PlaylistCollection_Unloaded(object sender, RoutedEventArgs e)
{
DetachHandlers();
}
private void DetachHandlers()
{
Unloaded -= PlaylistCollection_Unloaded;
}
}
}