private void OnPanelLoaded(object sender, RoutedEventArgs e)
 {
     _previewPanel = sender as ExpressionVerifierWrapPanel;
 }
        private void OnWindowClosed(object sender, EventArgs args)
        {
            var vm = sender as VerifyExpressionViewModel;
            if (vm == null)
                    return;

            if (_previewPanel != null)
            {
                var behaviorCollection = Interaction.GetBehaviors(_previewPanel);

                var moveBehavior =
                    behaviorCollection.FirstOrDefault(x => x is FluidMoveBehavior) as FluidMoveBehavior;

                if (moveBehavior != null)
                {
                    moveBehavior.IsActive = false;
                    moveBehavior.Detach();

                    behaviorCollection.Remove(moveBehavior);
                }

                foreach (var child in _previewPanel.Children)
                {
                    var cp = child as ContentPresenter;
                    if (cp != null)
                    {
                        cp.Content = null;
                        cp.ContentTemplate = null;
                        cp.DataContext = null;
                    }
                }

                _previewPanel.Children.Clear();
                _previewPanel = null;
            }

            _items.Clear();
            _treeViewItems.Clear();            
            _sourceFieldViewModels.Clear();

            _rootTreeViewItem.ClearSubItems();
            _rootTreeViewItem = null;

            ExpressionTestFields.Clear();

            DataContext = null;

            DataContextChanged -= OnDataContextChanged;
            vm.PropertyChanged -= OnDataContextPropertyChanged;
            vm.Closed -= OnWindowClosed;
        }