Browse Source

Make DesignWindowLoader expect PreviewWith on Styles.

pull/2307/head
Steven Kirk 8 years ago
parent
commit
c438f9301e
  1. 8
      samples/ControlCatalog/SideBar.xaml
  2. 6
      src/Avalonia.Controls/Design.cs
  3. 8
      src/Avalonia.DesignerSupport/DesignWindowLoader.cs

8
samples/ControlCatalog/SideBar.xaml

@ -1,6 +1,14 @@
<Styles xmlns="https://github.com/avaloniaui" <Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ControlCatalog.SideBar"> x:Class="ControlCatalog.SideBar">
<Design.PreviewWith>
<Border Padding="20">
<TabControl Classes="sidebar">
<TabItem Header="Item1"/>
<TabItem Header="Item2"/>
</TabControl>
</Border>
</Design.PreviewWith>
<Style Selector="TabControl.sidebar"> <Style Selector="TabControl.sidebar">
<Setter Property="TabStripPlacement" Value="Left"/> <Setter Property="TabStripPlacement" Value="Left"/>
<Setter Property="Padding" Value="8 0 0 0"/> <Setter Property="Padding" Value="8 0 0 0"/>

6
src/Avalonia.Controls/Design.cs

@ -48,14 +48,14 @@ namespace Avalonia.Controls
} }
public static readonly AttachedProperty<Control> PreviewWithProperty = AvaloniaProperty public static readonly AttachedProperty<Control> PreviewWithProperty = AvaloniaProperty
.RegisterAttached<Style, Control>("PreviewWith", typeof (Design)); .RegisterAttached<AvaloniaObject, Control>("PreviewWith", typeof (Design));
public static void SetPreviewWith(Style target, Control control) public static void SetPreviewWith(AvaloniaObject target, Control control)
{ {
target.SetValue(PreviewWithProperty, control); target.SetValue(PreviewWithProperty, control);
} }
public static Control GetPreviewWith(Style target) public static Control GetPreviewWith(AvaloniaObject target)
{ {
return target.GetValue(PreviewWithProperty); return target.GetValue(PreviewWithProperty);
} }

8
src/Avalonia.DesignerSupport/DesignWindowLoader.cs

@ -40,13 +40,13 @@ namespace Avalonia.DesignerSupport
var localAsm = assemblyPath != null ? Assembly.LoadFile(Path.GetFullPath(assemblyPath)) : null; var localAsm = assemblyPath != null ? Assembly.LoadFile(Path.GetFullPath(assemblyPath)) : null;
var loaded = loader.Load(stream, localAsm, null, baseUri); var loaded = loader.Load(stream, localAsm, null, baseUri);
var styles = loaded as Styles; var style = loaded as IStyle;
if (styles != null) if (style != null)
{ {
var substitute = styles.OfType<Style>().Select(Design.GetPreviewWith).FirstOrDefault(s => s != null); var substitute = Design.GetPreviewWith((AvaloniaObject)style);
if (substitute != null) if (substitute != null)
{ {
substitute.Styles.AddRange(styles); substitute.Styles.Add(style);
control = substitute; control = substitute;
} }
else else

Loading…
Cancel
Save