-
Notifications
You must be signed in to change notification settings - Fork 1
/
PegSelectionComponent.xaml.cs
38 lines (32 loc) · 1.23 KB
/
PegSelectionComponent.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Codebreaker.ViewModels;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.UI.Xaml.Media.Animation;
namespace CodeBreaker.WinUI.Views.Components;
internal sealed partial class PegSelectionComponent : UserControl, IRecipient<GameMoveMessage>
{
public PegSelectionComponent()
{
InitializeComponent();
WeakReferenceMessenger.Default.Register(this);
WeakReferenceMessenger.Default.UnregisterAllOnUnloaded(this);
}
public GamePageViewModel ViewModel
{
get => (GamePageViewModel)GetValue(ViewModelProperty);
set
{
SetValue(ViewModelProperty, value);
DataContext = ViewModel;
}
}
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel", typeof(GamePageViewModel), typeof(PegSelectionComponent), new PropertyMetadata(null));
public void Receive(GameMoveMessage message)
{
if (message.GameMoveValue is not GameMoveValue.Started)
return;
var animationService = ConnectedAnimationService.GetForCurrentView();
this.FindItemsOfType<ComboBox>(this)
.Foreach((comboBox, i) => animationService.PrepareToAnimate($"guess{i}", comboBox));
}
}