From d30d16b8553610552deb887915c6ab220889d83b Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Tue, 31 Oct 2017 04:43:50 -0700 Subject: [PATCH] Fixed issue with not being on dispatcher thread --- .../Views/Entities/EntityControlHost.xaml.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Torch.Server/Views/Entities/EntityControlHost.xaml.cs b/Torch.Server/Views/Entities/EntityControlHost.xaml.cs index bea6ada..f4a080f 100644 --- a/Torch.Server/Views/Entities/EntityControlHost.xaml.cs +++ b/Torch.Server/Views/Entities/EntityControlHost.xaml.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Threading; using System.Windows; using System.Windows.Controls; using Torch.Server.Managers; @@ -18,7 +19,7 @@ namespace Torch.Server.Views.Entities DataContextChanged += OnDataContextChanged; } - private void OnDataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) + private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (e.OldValue is ViewModel vmo) { @@ -43,6 +44,12 @@ namespace Torch.Server.Views.Entities private void RefreshControl() { + if (Dispatcher.Thread != Thread.CurrentThread) + { + Dispatcher.InvokeAsync(RefreshControl); + return; + } + _currentControl = DataContext is EntityControlViewModel ecvm ? TorchBase.Instance?.Managers.GetManager()?.CreateControl(ecvm) : null; @@ -52,6 +59,11 @@ namespace Torch.Server.Views.Entities private void RefreshVisibility() { + if (Dispatcher.Thread != Thread.CurrentThread) + { + Dispatcher.InvokeAsync(RefreshVisibility); + return; + } Visibility = (DataContext is EntityControlViewModel ecvm) && !ecvm.Hide && _currentControl != null ? Visibility.Visible : Visibility.Collapsed;