private static void OnEnableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uiElement = d as UIElement; if (uiElement != null) { var textBox = d as TextBox; if (((bool)e.NewValue) == true) { IUIElementView uiElementView = null; if (textBox != null) { uiElementView = new TextBoxView(textBox); } else { uiElementView = new UIElementView(uiElement); } // invoke on dispatcher, otherwise value does not take. Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { d.SetCurrentValue(UIElementViewProperty, uiElementView); })); } } }
public static void SetUIElementView(UIElement element, IUIElementView value) { element.SetValue(UIElementViewProperty, value); }