Skip to content

Commit

Permalink
Fixed crash when right clicking in PlaylistView
Browse files Browse the repository at this point in the history
  • Loading branch information
theweavrs committed Oct 27, 2016
1 parent 9643151 commit a8cee48
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
6 changes: 3 additions & 3 deletions BreadPlayer.Core/Behaviours/OpenMenuBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public object Execute(object sender, object parameter)
FrameworkElement senderElement = sender as FrameworkElement;
var navList = senderElement.GetFirstAncestorOfType<NavMenuListView>() != null && senderElement.GetFirstAncestorOfType<NavMenuListView>().Name == "PlaylistsMenuList" ? senderElement.GetFirstAncestorOfType<NavMenuListView>() : null;
ListViewItem item = senderElement.GetFirstAncestorOfType<ListViewItem>();
var ListBox = item.GetFirstAncestorOfType<ListView>();
var ListView = item.GetFirstAncestorOfType<ListView>();
// 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<Grid>().Where(t => t.Name == "LayoutRoot").ToList()[0].Resources["PlaylistsFlyout"] as BindableFlyout;
flyout.ShowAt(senderElement);
Expand All @@ -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<Grid>().Resources["Flyout"] as MenuFlyout;
flyout.ShowAt(senderElement, senderElement.GetPointerPosition());
Expand Down
4 changes: 2 additions & 2 deletions BreadPlayer.Core/ViewModels/PlaylistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListBox>().ToList()[0];
var fileBox = childern.OfType<ListView>().ToList()[0];
PlaylistSongsListBox = fileBox;
}
}
Expand Down
4 changes: 2 additions & 2 deletions BreadPlayer.Core/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ void PlayNext()

}
}
ListBox GetListBox()
ListView GetListBox()
{
if (PlaylistVM.IsPageLoaded)
{
return PlaylistVM.PlaylistSongsListBox;
}
else
{
return null; //LibVM.FileListBox;
return LibVM.FileListBox;
}
}
void PlayPrevious()
Expand Down
42 changes: 38 additions & 4 deletions BreadPlayer.Core/Views/PlaylistView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mc:Ignorable="d">
<Page.Resources>

<Style TargetType="ListBoxItem" x:Key="CustomPlaylistItemStyle">
<Style TargetType="ListViewItem" x:Key="CustomPlaylistItemStyle">
<Setter Property="Background" Value="Transparent" />
<Setter Property="TabNavigation" Value="Local" />
<Setter Property="Padding" Value="0" />
Expand All @@ -19,7 +19,7 @@

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ControlTemplate TargetType="ListViewItem">
<Grid DataContext="{Binding Source={StaticResource Core}, Path=LibVM}"
x:Name="LayoutRoot"
Background="{TemplateBinding Background}"
Expand Down Expand Up @@ -99,6 +99,14 @@
<VisualState.Setters>
<Setter Target="PressedBackground.Fill" Value="{ThemeResource HoverBrush}"/>
</VisualState.Setters>
<VisualState.Storyboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DataStack"
Storyboard.TargetProperty="CanDrag">
<DiscreteObjectKeyFrame KeyTime="0" Value="True" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState.Storyboard>
</VisualState>
<VisualState x:Name="SelectedUnfocused">
<VisualState.Setters>
Expand All @@ -115,7 +123,7 @@
</Storyboard>
</VisualState.Storyboard>
</VisualState>
<VisualState x:Name="SelectedPointerOver">
<VisualState x:Name="PointerOverSelected">
<VisualState.Setters>
<Setter Target="DataStack.Foreground" Value="{ThemeResource PointerOverBrush}"/>
<Setter Target="titleTxt.MaxWidth" Value="190"/>
Expand Down Expand Up @@ -146,6 +154,32 @@
</VisualState.Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="artistTxt.Visibility" Value="Collapsed"/>
<Setter Target="albumTxt.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="800"/>
</VisualState.StateTriggers>
<VisualState.Setters></VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="500"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="artistTxt.Visibility" Value="Visible"/>
<Setter Target="albumTxt.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle
x:Name="PressedBackground"
Expand Down Expand Up @@ -246,7 +280,7 @@
</StackPanel>
</Grid>
</Grid>
<ListBox x:Name="playListBox" Grid.Row="1" Background="{ThemeResource ThemeBackground}" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource CustomPlaylistItemStyle}"></ListBox>
<ListView x:Name="playListBox" Grid.Row="1" Background="{ThemeResource ThemeBackground}" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource CustomPlaylistItemStyle}"></ListView>
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="Loaded">
<Core:InvokeCommandAction Command="{Binding InitCommand}" CommandParameter="{Binding ElementName=Grid, Path=Children}"/>
Expand Down

0 comments on commit a8cee48

Please sign in to comment.