From 76aa5ee8d0eebd66171acc17afc51143d95f615d Mon Sep 17 00:00:00 2001 From: Zhe Fang Date: Fri, 19 Dec 2025 14:46:23 -0500 Subject: [PATCH] fix: search control result can not invoke play selected lyrics line --- .../Controls/LyricsSearchControl.xaml | 45 ++++++++++++++----- .../Controls/LyricsSearchControl.xaml.cs | 6 +-- .../LyricsSearchControlViewModel.cs | 21 ++++----- .../Views/LyricsSearchWindow.xaml.cs | 2 +- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml index ba421f8..dda07c9 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml @@ -278,18 +278,43 @@ - + - - - - - - + + + + + + + + + + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml.cs index e39798e..8a2035b 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/LyricsSearchControl.xaml.cs @@ -18,10 +18,10 @@ namespace BetterLyrics.WinUI3.Controls DataContext = Ioc.Default.GetRequiredService(); } - private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) + private void PlayLyricsLineButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { - ViewModel.SelectedLyricsLine = e.OriginalSource as LyricsLine; + var lyricsLine = (LyricsLine)((Button)sender).DataContext; + ViewModel.PlayLyricsLine(lyricsLine); } - } } diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs index 1b0aaf9..7a29eeb 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/ViewModels/LyricsSearchControlViewModel.cs @@ -37,9 +37,6 @@ namespace BetterLyrics.WinUI3.ViewModels [ObservableProperty] public partial ObservableCollection? LyricsDataArr { get; set; } - [ObservableProperty] - public partial LyricsLine? SelectedLyricsLine { get; set; } - [ObservableProperty] public partial MappedSongSearchQuery? MappedSongSearchQuery { get; set; } @@ -99,6 +96,15 @@ namespace BetterLyrics.WinUI3.ViewModels return found; } + public void PlayLyricsLine(LyricsLine? value) + { + if (value?.StartMs == null) + { + return; + } + _mediaSessionsService.ChangePosition(value.StartMs / 1000.0); + } + [RelayCommand] private void Search() { @@ -188,15 +194,6 @@ namespace BetterLyrics.WinUI3.ViewModels } } - partial void OnSelectedLyricsLineChanged(LyricsLine? value) - { - if (value?.StartMs == null) - { - return; - } - _mediaSessionsService.ChangePosition(value.StartMs / 1000.0); - } - public void Receive(PropertyChangedMessage message) { if (message.Sender is IMediaSessionsService) diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsSearchWindow.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsSearchWindow.xaml.cs index cf5d86d..6a4ffeb 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsSearchWindow.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/LyricsSearchWindow.xaml.cs @@ -18,7 +18,7 @@ namespace BetterLyrics.WinUI3.Views { InitializeComponent(); - this.Init("LyricsSearchPageTitle", backdropType: BackdropType.Transparent); + this.Init("LyricsSearchPageTitle"); AppWindow.Closing += AppWindow_Closing; }