From 6ac967994729520fc430072fa2baa98d9ef0745f Mon Sep 17 00:00:00 2001 From: Royce551 Date: Thu, 15 Jul 2021 16:21:55 -0500 Subject: [PATCH] actually unsubscribe to events --- .../FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml | 2 +- .../FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml.cs | 6 ++++++ .../FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml index cac2f54..e03829b 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml @@ -6,7 +6,7 @@ xmlns:vm="using:FRESHMusicPlayer.ViewModels" xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties" mc:Ignorable="d" Width="500" Height="300" - x:Class="FRESHMusicPlayer.Views.Lyrics" WindowStartupLocation="CenterOwner" + x:Class="FRESHMusicPlayer.Views.Lyrics" WindowStartupLocation="CenterOwner" Closing="OnClosing" Title="{x:Static resx:Resources.Lyrics}"> diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml.cs index b7eedb0..b090527 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml.cs @@ -2,6 +2,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using FRESHMusicPlayer.ViewModels; +using System.ComponentModel; namespace FRESHMusicPlayer.Views { @@ -23,6 +24,11 @@ namespace FRESHMusicPlayer.Views return this; } + private void OnClosing(object sender, CancelEventArgs e) + { + (DataContext as LyricsViewModel)?.Deinitialize(); + } + private void InitializeComponent() { AvaloniaXamlLoader.Load(this); diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs index b5e4b9b..4a1f0c7 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs @@ -117,7 +117,7 @@ namespace FRESHMusicPlayer.Views ViewModel.Volume += ((float)((e.Delta.Y) / 100) * 3); } - private void OnKeyDown(object sender, KeyEventArgs e) + private async void OnKeyDown(object sender, KeyEventArgs e) { if (e.Source is not TextBox or ListBoxItem) switch (e.Key) @@ -155,6 +155,11 @@ namespace FRESHMusicPlayer.Views } switch (e.Key) { + case Key.OemTilde: + var dialog = new TextEntryBox().SetStuff(Properties.Resources.FilePathOrUrl); + await dialog.ShowDialog(this); + if (dialog.OK) ViewModel.Player.PlayMusic((dialog.DataContext as TextEntryBoxViewModel).Text); + break; case Key.F1: InterfaceUtils.OpenURL("https://royce551.github.io/FRESHMusicPlayer/docs/index.html"); break;