Skip to content

Commit

Permalink
Scroll to top of database tabs when changing content.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Nov 25, 2023
1 parent 51a500c commit 0e48309
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Happy Reader/View/Tabs/DatabaseTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
if (_loaded) return;
if (DesignerProperties.GetIsInDesignMode(this)) return;
ViewModel = (DatabaseViewModelBase)DataContext;
ViewModel.ScrollToTop = ScrollToTop;
_loaded = true;
}

Expand Down Expand Up @@ -184,5 +185,12 @@ private void OpenVNPanel(MouseEventArgs e, FrameworkElement element, bool switch
if (vn == null) return;
StaticMethods.MainWindow.OpenVNPanel(vn, switchToTab);
}

private void ScrollToTop()
{
var firstItem = VisualNovelItems.Items[0];
if(firstItem == null) return;
VisualNovelItems.ScrollIntoView(firstItem);
}
}
}
5 changes: 3 additions & 2 deletions Happy Reader/ViewModel/DatabaseViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public SuggestionScorer SuggestionScorer
}
}
public TitleOrderingType OrderingType { get; private set; }
public Action ScrollToTop { get; set; }

protected DatabaseViewModelBase(MainWindowViewModel mainWindowViewModel)
{
Expand Down Expand Up @@ -210,8 +211,8 @@ protected async Task RefreshTiles()
OnPropertyChanged(nameof(CSettings));
OnPropertyChanged(nameof(Tiles));
OnPropertyChanged(nameof(AllResults));

});
ScrollToTop?.Invoke();
});
watch.Stop();
SetReplyText($"Loaded results in {watch.Elapsed.ToSeconds()}.", VndbConnection.MessageSeverity.Normal);

Expand Down

0 comments on commit 0e48309

Please sign in to comment.