Skip to content

Commit a2eb563

Browse files
committed
Made ScrollViewer automatically scroll to last move
1 parent 059479f commit a2eb563

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/CodeBreaker.Avalonia/CodeBreaker.Avalonia/Views/Pages/GamePage.axaml.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@
22
using Avalonia.Interactivity;
33
using Codebreaker.ViewModels;
44
using Codebreaker.ViewModels.Contracts.Services;
5+
using CommunityToolkit.Mvvm.Messaging;
56

67
namespace CodeBreaker.Avalonia.Views.Pages;
78

8-
public partial class GamePage : UserControl
9+
public partial class GamePage : UserControl, IRecipient<GameMoveMessage>
910
{
1011
private readonly INavigationService _navigationService;
1112

1213
public GamePage()
1314
{
1415
DataContext = App.Current.GetService<GamePageViewModel>();
15-
InitializeComponent();
1616
_navigationService = App.Current.GetService<INavigationService>();
17+
InitializeComponent();
18+
WeakReferenceMessenger.Default.Register(this);
19+
}
20+
21+
protected override void OnUnloaded(RoutedEventArgs e)
22+
{
23+
WeakReferenceMessenger.Default.UnregisterAll(this);
1724
}
1825

1926
public GamePageViewModel ViewModel => (GamePageViewModel)DataContext!;
2027

28+
public void Receive(GameMoveMessage message)
29+
{
30+
if (message.GameMoveValue is not GameMoveValue.Completed)
31+
return;
32+
33+
pegScrollViewer.UpdateLayout();
34+
pegScrollViewer.ScrollToEnd();
35+
}
36+
2137
private void ToTestPageButtonClicked(object? sender, RoutedEventArgs e)
2238
{
2339
_navigationService.NavigateToAsync("TestPage");

0 commit comments

Comments
 (0)