diff --git a/src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs b/src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs index 5125450819c..440b279fee8 100644 --- a/src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs +++ b/src/DynamoCoreWpf/Views/Preview/PreviewControl.xaml.cs @@ -393,10 +393,7 @@ private void RefreshExpandedDisplay(Action refreshDisplay) if (largeContentGrid.Children.Count == 0) { - var tree = new WatchTree - { - DataContext = new WatchViewModel(nodeViewModel.DynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath) - }; + var tree = new WatchTree(new WatchViewModel(nodeViewModel.DynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath)); tree.treeView1.ItemContainerGenerator.StatusChanged += WatchContainer_StatusChanged; largeContentGrid.Children.Add(tree); } diff --git a/src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs b/src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs index 433441671b3..886f545dfc7 100644 --- a/src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs +++ b/src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs @@ -22,9 +22,13 @@ public partial class WatchTree : UserControl private readonly int minWidthSize = 100; private readonly int minHeightSize = 38; - public WatchTree() + public WatchTree(WatchViewModel vm) { + _vm = vm; + InitializeComponent(); + + DataContext = vm; this.Loaded += WatchTree_Loaded; this.Unloaded += WatchTree_Unloaded; } @@ -42,8 +46,7 @@ private void WatchTree_Unloaded(object sender, RoutedEventArgs e) void WatchTree_Loaded(object sender, RoutedEventArgs e) { - _vm = this.DataContext as WatchViewModel; - _vm.PropertyChanged += _vm_PropertyChanged; + _vm.PropertyChanged += _vm_PropertyChanged; } private void _vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Watch.cs b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Watch.cs index 63913e2e26c..4c5c11d23dd 100644 --- a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Watch.cs +++ b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/Watch.cs @@ -39,15 +39,15 @@ public void CustomizeView(Watch nodeModel, NodeView nodeView) this.watch = nodeModel; this.syncContext = new DispatcherSynchronizationContext(nodeView.Dispatcher); - var watchTree = new WatchTree(); + // make empty watchViewModel + rootWatchViewModel = new WatchViewModel(dynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath); + + var watchTree = new WatchTree(rootWatchViewModel); watchTree.BorderThickness = new Thickness(1, 1, 1, 1); watchTree.BorderBrush = new SolidColorBrush(Color.FromRgb(220,220,220)); watchTree.SetWatchNodeProperties(); - // make empty watchViewModel - rootWatchViewModel = new WatchViewModel(dynamoViewModel.BackgroundPreviewViewModel.AddLabelForPath); - nodeView.PresentationGrid.Children.Add(watchTree); nodeView.PresentationGrid.Visibility = Visibility.Visible; // disable preview control @@ -61,9 +61,6 @@ public void CustomizeView(Watch nodeModel, NodeView nodeView) private void Bind(WatchTree watchTree, NodeView nodeView) { - // The WatchTree Control is bound to the WatchViewModel - watchTree.DataContext = rootWatchViewModel; - // Add binding for TreeView var sourceBinding = new Binding("Children") { diff --git a/test/DynamoCoreWpfTests/DynamoViewTests.cs b/test/DynamoCoreWpfTests/DynamoViewTests.cs index 5884100c51e..d470873fffa 100644 --- a/test/DynamoCoreWpfTests/DynamoViewTests.cs +++ b/test/DynamoCoreWpfTests/DynamoViewTests.cs @@ -24,7 +24,7 @@ namespace DynamoCoreWpfTests -{ +{ public class DynamoViewTests : DynamoTestUIBase { // adapted from: NodeViewTests.cs @@ -58,11 +58,11 @@ public void FooterNotificationControlTest() var workspace = ViewModel.Model.CurrentWorkspace as HomeWorkspaceModel; Debug.Assert(workspace != null, nameof(workspace) + " != null"); - workspace.Run(); + workspace.Run(); List errorNodes = ViewModel.Model.CurrentWorkspace.Nodes.ToList().FindAll(n => n.State == ElementState.Error); List warningNodes = ViewModel.Model.CurrentWorkspace.Nodes.ToList().FindAll(n => n.State == ElementState.Warning || n.State == ElementState.PersistentWarning); - + // We should have 3 nodes in Error state and 3 nodes in Warning state Assert.AreEqual(3, warningNodes.Count()); Assert.AreEqual(3, errorNodes.Count()); @@ -92,7 +92,7 @@ public void FooterNotificationControlTest() // Check if the run message indicates warning Assert.AreEqual(notificationsControl.runNotificationTextBlock.Text, "Run completed with warnings."); - + // After deleting all Error nodes, the counter should get to 0 Assert.AreEqual((items[0] as FooterNotificationItem).NotificationCount, 0);