Hooked up view with play button

Set up data structures for holding and playing music
This commit is contained in:
watsonb8
2019-05-22 10:30:41 -04:00
parent 65d56a838c
commit a4276a0d5d
7 changed files with 88 additions and 31 deletions

View File

@ -4,13 +4,23 @@ using System.Runtime.CompilerServices;
namespace Aurora.Frontend.Views
{
public class BaseViewModel
public class BaseViewModel : INotifyPropertyChanged
{
public BaseViewModel()
{
}
#region INotifyPropertyChanged Implementation
public bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Object.Equals(storage, value))
return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{

View File

@ -1,11 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:songs="clr-namespace:Aurora.Frontend.Views.Songs"
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
x:Class="Aurora.Frontend.Views.Songs.SongsView">
<ContentPage.BindingContext>
<songs:SongsViewModel x:Name="songsViewModel"/>
</ContentPage.BindingContext>
<ContentPage.Content>
<dg:DataGrid ItemsSource="{Binding SongsList}" SelectionEnabled="True" SelectedItem="{Binding SelectedSong}"
RowHeight="30" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8">
RowHeight="30" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8" >
<!-- Header -->
<dg:DataGrid.HeaderFontSize>
@ -18,7 +23,14 @@
<!-- Columns -->
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="Title" PropertyName="Title" Width="2*"/>
<dg:DataGridColumn Title="" Width="40">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<Button Text="Play" Command="{Binding PlayCommand}" BindingContext="{x:Reference songsViewModel}" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn Title="Title" PropertyName="Title" Width="2*" />
<dg:DataGridColumn Title="Album" PropertyName="Album" Width="0.95*"/>
<dg:DataGridColumn Title="Artist" PropertyName="Artist" Width="1*"/>
<dg:DataGridColumn Title="Duration" PropertyName="Duration"/>

View File

@ -10,7 +10,6 @@ namespace Aurora.Frontend.Views.Songs
public SongsView()
{
InitializeComponent();
BindingContext = new SongsViewModel();
}
}
}

View File

@ -1,6 +1,8 @@
using System.Collections.ObjectModel;
using Aurora.Backend.Models;
using Aurora.Backend.Services;
using Aurora.Backend.Services.PlayerService;
using Xamarin.Forms;
namespace Aurora.Frontend.Views.Songs
{
@ -16,6 +18,7 @@ namespace Aurora.Frontend.Views.Songs
public SongsViewModel()
{
_songsList = new ObservableCollection<BaseSong>();
PlayCommand = new Command(PlayExecute);
Initialize();
}
@ -25,29 +28,17 @@ namespace Aurora.Frontend.Views.Songs
public ObservableCollection<BaseSong> SongsList
{
get { return _songsList; }
set
{
if (value != _songsList)
{
_songsList = value;
OnPropertyChanged("SongList");
}
}
set { SetProperty(ref _songsList, value); }
}
public BaseSong SelectedSong
{
get { return _selectedSong; }
set
{
if (value != _selectedSong)
{
_selectedSong = value;
OnPropertyChanged("SelectedSong");
}
}
set { SetProperty(ref _selectedSong, value); }
}
public Command PlayCommand { get; private set; }
#endregion Properties
#region Methods