From 943d885ac94769fbece33dc6b05266618abe5d12 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Fri, 19 Jan 2024 08:40:42 +0100 Subject: [PATCH 1/2] fix: #175 set the DataContext earlier to prevent binding errors --- MsBox.Avalonia/Controls/MsBoxCustomView.axaml.cs | 3 ++- MsBox.Avalonia/Controls/MsBoxStandardView.axaml.cs | 3 ++- MsBox.Avalonia/MessageBoxManager.cs | 10 ++-------- MsBox.Avalonia/MsBox.cs | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/MsBox.Avalonia/Controls/MsBoxCustomView.axaml.cs b/MsBox.Avalonia/Controls/MsBoxCustomView.axaml.cs index f97660b..f07a3cd 100644 --- a/MsBox.Avalonia/Controls/MsBoxCustomView.axaml.cs +++ b/MsBox.Avalonia/Controls/MsBoxCustomView.axaml.cs @@ -11,8 +11,9 @@ public partial class MsBoxCustomView : UserControl, IFullApi, ISetCloseA private string _buttonResult; private Action _closeAction; - public MsBoxCustomView() + public MsBoxCustomView(AbstractMsBoxViewModel viewModel) { + this.DataContext = viewModel; InitializeComponent(); } diff --git a/MsBox.Avalonia/Controls/MsBoxStandardView.axaml.cs b/MsBox.Avalonia/Controls/MsBoxStandardView.axaml.cs index 2bfed7a..88db496 100644 --- a/MsBox.Avalonia/Controls/MsBoxStandardView.axaml.cs +++ b/MsBox.Avalonia/Controls/MsBoxStandardView.axaml.cs @@ -13,8 +13,9 @@ public partial class MsBoxStandardView : UserControl, IFullApi, IS private ButtonResult _buttonResult = ButtonResult.None; private Action _closeAction; - public MsBoxStandardView() + public MsBoxStandardView(AbstractMsBoxViewModel viewModel) { + this.DataContext = viewModel; InitializeComponent(); } diff --git a/MsBox.Avalonia/MessageBoxManager.cs b/MsBox.Avalonia/MessageBoxManager.cs index 6994b59..43d8b15 100644 --- a/MsBox.Avalonia/MessageBoxManager.cs +++ b/MsBox.Avalonia/MessageBoxManager.cs @@ -12,20 +12,14 @@ public static class MessageBoxManager public static IMsBox GetMessageBoxCustom(MessageBoxCustomParams @params) { var msBoxCustomViewModel = new MsBoxCustomViewModel(@params); - var msBoxCustomView = new MsBoxCustomView - { - DataContext = msBoxCustomViewModel - }; + var msBoxCustomView = new MsBoxCustomView(msBoxCustomViewModel); return new MsBox(msBoxCustomView, msBoxCustomViewModel); } public static IMsBox GetMessageBoxStandard(MessageBoxStandardParams @params) { var msBoxStandardViewModel = new MsBoxStandardViewModel(@params); - var msBoxStandardView = new MsBoxStandardView - { - DataContext = msBoxStandardViewModel - }; + var msBoxStandardView = new MsBoxStandardView(msBoxStandardViewModel); return new MsBox(msBoxStandardView, msBoxStandardViewModel); } diff --git a/MsBox.Avalonia/MsBox.cs b/MsBox.Avalonia/MsBox.cs index df7c60b..5185bf7 100644 --- a/MsBox.Avalonia/MsBox.cs +++ b/MsBox.Avalonia/MsBox.cs @@ -55,8 +55,8 @@ public Task ShowWindowAsync() { _viewModel.SetFullApi(_view); var window = new MsBoxWindow(); - window.Content = _view; window.DataContext = _viewModel; + window.Content = _view; window.Closed += _view.CloseWindow; var tcs = new TaskCompletionSource(); @@ -80,8 +80,8 @@ public Task ShowWindowDialogAsync(Window owner) { _viewModel.SetFullApi(_view); var window = new MsBoxWindow(); - window.Content = _view; window.DataContext = _viewModel; + window.Content = _view; window.Closed += _view.CloseWindow; var tcs = new TaskCompletionSource(); From ff8910ade8369995679a551c31c85dc026f42e64 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Fri, 19 Jan 2024 08:41:15 +0100 Subject: [PATCH 2/2] chore(deps): #175 update to Avalonia 11.0.7 --- Exmaple2.0/Exmaple2.0.csproj | 10 +++++----- MsBox.Avalonia/MsBox.Avalonia.csproj | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Exmaple2.0/Exmaple2.0.csproj b/Exmaple2.0/Exmaple2.0.csproj index e26b362..3e1816d 100644 --- a/Exmaple2.0/Exmaple2.0.csproj +++ b/Exmaple2.0/Exmaple2.0.csproj @@ -19,11 +19,11 @@ - - - - - + + + + + diff --git a/MsBox.Avalonia/MsBox.Avalonia.csproj b/MsBox.Avalonia/MsBox.Avalonia.csproj index b2f4ae5..bda8630 100644 --- a/MsBox.Avalonia/MsBox.Avalonia.csproj +++ b/MsBox.Avalonia/MsBox.Avalonia.csproj @@ -1,4 +1,4 @@ - + 3.1.5.1 @@ -26,7 +26,7 @@ - +