/// <summary> /// テンプレート変更時のヘルパ /// </summary> /// <param name="target">対象とする DependencyObject を指定します。</param> private static void OnChange(DependencyObject target) { var element = target as FrameworkElement; // Loaded イベント以前は AdornerLayer が null になってしまうので実行しない if (!element.IsLoaded) { return; } var template = GetDataTemplate(element); var isEnabled = GetIsEnabled(element); var adorner = element.GetValue(AdornerCore.AdornerProperty) as AdornerCore; if (isEnabled) { if (adorner == null) { if ((element != null) && (template != null)) { var frameworkElement = template.LoadContent() as FrameworkElement; adorner = new AdornerCore(element, frameworkElement); element.SetValue(AdornerCore.AdornerProperty, adorner); SetAdornerDataContext(target); } } else { adorner.Attach(); } } else { if (adorner != null) { adorner.Detach(); } } }
/// <summary> /// テンプレート変更時のヘルパ /// </summary> /// <param name="target">対象とする DependencyObject を指定します。</param> private static void OnChange(DependencyObject target) { var element = target as FrameworkElement; var template = GetDataTemplate(element); var isEnabled = GetIsEnabled(element); var adorner = element.GetValue(AdornerCore.AdornerProperty) as AdornerCore; if (isEnabled) { if (adorner == null) { if ((element != null) && (template != null)) { var frameworkElement = template.LoadContent() as FrameworkElement; adorner = new AdornerCore(element, frameworkElement); element.SetValue(AdornerCore.AdornerProperty, adorner); SetAdornerDataContext(target); } } else { adorner.Attach(); } } else { if (adorner != null) { adorner.Detach(); } } }