diff --git a/src/Avalonia.Controls/Design.cs b/src/Avalonia.Controls/Design.cs index ce52891749..894240a09f 100644 --- a/src/Avalonia.Controls/Design.cs +++ b/src/Avalonia.Controls/Design.cs @@ -1,5 +1,6 @@ using System.Runtime.CompilerServices; +using Avalonia.Styling; namespace Avalonia.Controls { @@ -45,23 +46,18 @@ namespace Avalonia.Controls { return control.GetValue(DataContextProperty); } - - static readonly ConditionalWeakTable Substitutes = new ConditionalWeakTable(); - + public static readonly AttachedProperty PreviewWithProperty = AvaloniaProperty - .RegisterAttached("PreviewWith", typeof (Design)); + .RegisterAttached("PreviewWith", typeof (Design)); - public static void SetPreviewWith(object target, Control control) + public static void SetPreviewWith(Style target, Control control) { - Substitutes.Remove(target); - Substitutes.Add(target, control); + target.SetValue(PreviewWithProperty, control); } - public static Control GetPreviewWith(object target) + public static Control GetPreviewWith(Style target) { - Control rv; - Substitutes.TryGetValue(target, out rv); - return rv; + return target.GetValue(PreviewWithProperty); } public static void ApplyDesignModeProperties(Control target, Control source) diff --git a/src/Avalonia.DesignerSupport/DesignWindowLoader.cs b/src/Avalonia.DesignerSupport/DesignWindowLoader.cs index d1958ac9bf..6dca479d38 100644 --- a/src/Avalonia.DesignerSupport/DesignWindowLoader.cs +++ b/src/Avalonia.DesignerSupport/DesignWindowLoader.cs @@ -36,8 +36,7 @@ namespace Avalonia.DesignerSupport var styles = loaded as Styles; if (styles != null) { - var substitute = Design.GetPreviewWith(styles) ?? - styles.Select(Design.GetPreviewWith).FirstOrDefault(s => s != null); + var substitute = styles.OfType