From ac26faa1b432182d60763e139caf06d05c2ff2ff Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 20 Feb 2024 14:30:46 +0200 Subject: [PATCH] Fix binding issue for Uno --- .../Views/Components/PegSelectionComponent.xaml.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Codebreaker.Uno/CodebreakerUno/Views/Components/PegSelectionComponent.xaml.cs b/src/Codebreaker.Uno/CodebreakerUno/Views/Components/PegSelectionComponent.xaml.cs index f661267a..dcb70054 100644 --- a/src/Codebreaker.Uno/CodebreakerUno/Views/Components/PegSelectionComponent.xaml.cs +++ b/src/Codebreaker.Uno/CodebreakerUno/Views/Components/PegSelectionComponent.xaml.cs @@ -17,15 +17,17 @@ public PegSelectionComponent() public GamePageViewModel ViewModel { get => (GamePageViewModel)GetValue(ViewModelProperty); - set - { - SetValue(ViewModelProperty, value); - DataContext = ViewModel; - } + set => SetValue(ViewModelProperty, value); } public static readonly DependencyProperty ViewModelProperty = - DependencyProperty.Register("ViewModel", typeof(GamePageViewModel), typeof(PegSelectionComponent), new PropertyMetadata(null)); + DependencyProperty.Register("ViewModel", typeof(GamePageViewModel), typeof(PegSelectionComponent), new PropertyMetadata(null, propertyChangedCallback: OnViewModelChanged)); + + private static void OnViewModelChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) + { + var @this = (PegSelectionComponent)dependencyObject; + @this.DataContext = (GamePageViewModel)args.NewValue; + } public void Receive(GameMoveMessage message) {