Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DesignStyle property #6617

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Avalonia.Controls/Design.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public static Control GetPreviewWith(AvaloniaObject target)
return target.GetValue(PreviewWithProperty);
}

public static readonly AttachedProperty<IStyle> DesignStyleProperty = AvaloniaProperty
.RegisterAttached<Control, IStyle>("DesignStyle", typeof(Design));

public static void SetDesignStyle(Control control, IStyle value)
{
control.SetValue(DesignStyleProperty, value);
}

public static IStyle GetDesignStyle(Control control)
{
return control.GetValue(DesignStyleProperty);
}

public static void ApplyDesignModeProperties(Control target, Control source)
{
if (source.IsSet(WidthProperty))
Expand All @@ -68,6 +81,8 @@ public static void ApplyDesignModeProperties(Control target, Control source)
target.Height = source.GetValue(HeightProperty);
if (source.IsSet(DataContextProperty))
target.DataContext = source.GetValue(DataContextProperty);
if (source.IsSet(DesignStyleProperty))
target.Styles.Add(source.GetValue(DesignStyleProperty));
}
}
}