From a8cee48f8e64bc52f23005823247f8d2db301804 Mon Sep 17 00:00:00 2001 From: theweavrs Date: Fri, 28 Oct 2016 03:29:07 +0500 Subject: [PATCH] Fixed crash when right clicking in PlaylistView --- .../Behaviours/OpenMenuBehaviour.cs | 6 +-- .../ViewModels/PlaylistViewModel.cs | 4 +- BreadPlayer.Core/ViewModels/ShellViewModel.cs | 4 +- BreadPlayer.Core/Views/PlaylistView.xaml | 42 +++++++++++++++++-- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/BreadPlayer.Core/Behaviours/OpenMenuBehaviour.cs b/BreadPlayer.Core/Behaviours/OpenMenuBehaviour.cs index 6a76abc..d0e1e26 100644 --- a/BreadPlayer.Core/Behaviours/OpenMenuBehaviour.cs +++ b/BreadPlayer.Core/Behaviours/OpenMenuBehaviour.cs @@ -51,14 +51,14 @@ public object Execute(object sender, object parameter) FrameworkElement senderElement = sender as FrameworkElement; var navList = senderElement.GetFirstAncestorOfType() != null && senderElement.GetFirstAncestorOfType().Name == "PlaylistsMenuList" ? senderElement.GetFirstAncestorOfType() : null; ListViewItem item = senderElement.GetFirstAncestorOfType(); - var ListBox = item.GetFirstAncestorOfType(); + var ListView = item.GetFirstAncestorOfType(); // if (item != null) item.IsSelected = true; ListViewItem listItem = senderElement.Tag is ContentPresenter ? (senderElement.Tag as ContentPresenter).Tag as ListViewItem : null; if(listItem != null) listItem.IsSelected = true; //var items = //((Parameter as Binding).Path as ListViewItem); if (Parameter.ToString() == "BindableFlyout") { - if (ListBox?.SelectedItems.Count == 1) { ListBox.SelectedIndex = -1; } + if (ListView?.SelectedItems.Count == 1) { ListView.SelectedIndex = -1; } if (item != null) item.IsSelected = true; var flyout = (senderElement as Button).GetAncestorsOfType().Where(t => t.Name == "LayoutRoot").ToList()[0].Resources["PlaylistsFlyout"] as BindableFlyout; flyout.ShowAt(senderElement); @@ -74,7 +74,7 @@ public object Execute(object sender, object parameter) } else { - ListBox.SelectedIndex = -1; + ListView.SelectedIndex = -1; if (item != null) item.IsSelected = true; var flyout = senderElement.Resources["Flyout"] as MenuFlyout; //.GetFirstDescendantOfType().Resources["Flyout"] as MenuFlyout; flyout.ShowAt(senderElement, senderElement.GetPointerPosition()); diff --git a/BreadPlayer.Core/ViewModels/PlaylistViewModel.cs b/BreadPlayer.Core/ViewModels/PlaylistViewModel.cs index 5f9432f..7fe42f1 100644 --- a/BreadPlayer.Core/ViewModels/PlaylistViewModel.cs +++ b/BreadPlayer.Core/ViewModels/PlaylistViewModel.cs @@ -218,14 +218,14 @@ public ICommand InitCommand get { if (_initCommand == null) { _initCommand = new RelayCommand(param => this.Init(param)); } return _initCommand; } } - public ListBox PlaylistSongsListBox; + public ListView PlaylistSongsListBox; bool _isPageLoaded; public bool IsPageLoaded { get { return _isPageLoaded; } set { Set(ref _isPageLoaded, value); } } void Init(object para) { IsPageLoaded = true; var childern = para as UIElementCollection; - var fileBox = childern.OfType().ToList()[0]; + var fileBox = childern.OfType().ToList()[0]; PlaylistSongsListBox = fileBox; } } diff --git a/BreadPlayer.Core/ViewModels/ShellViewModel.cs b/BreadPlayer.Core/ViewModels/ShellViewModel.cs index a1a61e5..791568f 100644 --- a/BreadPlayer.Core/ViewModels/ShellViewModel.cs +++ b/BreadPlayer.Core/ViewModels/ShellViewModel.cs @@ -115,7 +115,7 @@ void PlayNext() } } - ListBox GetListBox() + ListView GetListBox() { if (PlaylistVM.IsPageLoaded) { @@ -123,7 +123,7 @@ ListBox GetListBox() } else { - return null; //LibVM.FileListBox; + return LibVM.FileListBox; } } void PlayPrevious() diff --git a/BreadPlayer.Core/Views/PlaylistView.xaml b/BreadPlayer.Core/Views/PlaylistView.xaml index e60013a..6abf826 100644 --- a/BreadPlayer.Core/Views/PlaylistView.xaml +++ b/BreadPlayer.Core/Views/PlaylistView.xaml @@ -10,7 +10,7 @@ mc:Ignorable="d"> -