using System.Threading.Tasks;
using OwlCore.Extensions;
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 ArtistCollection : CollectionControl
{
///
/// Initializes a new instance of the class.
///
public ArtistCollection()
{
this.DefaultStyleKey = typeof(ArtistCollection);
}
///
/// Backing dependency property for .
///
public IArtistCollectionViewModel Collection
{
get { return (IArtistCollectionViewModel)GetValue(CollectionProperty); }
set { SetValue(CollectionProperty, value); }
}
///
/// Dependency property for .
///
public static readonly DependencyProperty CollectionProperty =
DependencyProperty.Register(nameof(Collection), typeof(IArtistCollectionViewModel), typeof(ArtistCollection), 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();
}
private void AttachHandlers()
{
Unloaded += ArtistCollection_Unloaded;
}
private void DetachHandlers()
{
Unloaded -= ArtistCollection_Unloaded;
}
///
protected override async Task LoadMore()
{
if (Collection != null && !Collection.PopulateMoreArtistsCommand.IsRunning)
await Collection.PopulateMoreArtistsCommand.ExecuteAsync(25);
}
///
protected override void CheckAndToggleEmpty()
{
if (Collection != null && !Collection.PopulateMoreArtistsCommand.IsRunning && Collection.TotalArtistItemsCount == 0)
SetEmptyVisibility(Visibility.Visible);
}
private void ArtistCollection_Unloaded(object sender, RoutedEventArgs e)
{
DetachHandlers();
}
}
}