public DisplayItemViewModel(DisplayContainerViewModel parent, UIElement control) { // Setup initial conditions. this.parent = parent; displaySettings = TestHarnessModel.Instance.Settings.ControlDisplayOptionSettings; // Ensure the item is not already within the visual tree. var parentBorder = control.GetParentVisual() as Border; if (parentBorder != null) parentBorder.Child = null; // Create it's container. Control = control; ControlContainer = new Border { Child = control }; // Wire up events. ControlContainer.Loaded += delegate { InitializeContainerSize(); }; viewTestClassObserver = new PropertyObserver<ViewTestClass>(parent.model) .RegisterHandler(m => m.CurrentViewTest, m => InitializeContainerSize()); displaySettingsObserver = new PropertyObserver<ControlDisplayOptionSettings>(displaySettings) .RegisterHandler(s => s.ShowBorder, s => OnPropertyChanged<DisplayItemViewModel>(m => m.Border)); }