csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.6 KiB
77 lines
2.6 KiB
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Avalonia.Controls
|
|
{
|
|
public static class Design
|
|
{
|
|
public static bool IsDesignMode { get; internal set; }
|
|
|
|
public static readonly AttachedProperty<double> HeightProperty = AvaloniaProperty
|
|
.RegisterAttached<Control, double>("Height", typeof (Design));
|
|
|
|
public static void SetHeight(Control control, double value)
|
|
{
|
|
control.SetValue(HeightProperty, value);
|
|
}
|
|
|
|
public static double GetHeight(Control control)
|
|
{
|
|
return control.GetValue(HeightProperty);
|
|
}
|
|
|
|
public static readonly AttachedProperty<double> WidthProperty = AvaloniaProperty
|
|
.RegisterAttached<Control, double>("Width", typeof(Design));
|
|
|
|
public static void SetWidth(Control control, double value)
|
|
{
|
|
control.SetValue(WidthProperty, value);
|
|
}
|
|
|
|
public static double GetWidth(Control control)
|
|
{
|
|
return control.GetValue(WidthProperty);
|
|
}
|
|
|
|
public static readonly AttachedProperty<object> DataContextProperty = AvaloniaProperty
|
|
.RegisterAttached<Control, object>("DataContext", typeof (Design));
|
|
|
|
public static void SetDataContext(Control control, object value)
|
|
{
|
|
control.SetValue(DataContextProperty, value);
|
|
}
|
|
|
|
public static object GetDataContext(Control control)
|
|
{
|
|
return control.GetValue(DataContextProperty);
|
|
}
|
|
|
|
static readonly ConditionalWeakTable<object, Control> Substitutes = new ConditionalWeakTable<object, Control>();
|
|
|
|
public static readonly AttachedProperty<Control> PreviewWithProperty = AvaloniaProperty
|
|
.RegisterAttached<AvaloniaObject, Control>("PreviewWith", typeof (Design));
|
|
|
|
public static void SetPreviewWith(object target, Control control)
|
|
{
|
|
Substitutes.Remove(target);
|
|
Substitutes.Add(target, control);
|
|
}
|
|
|
|
public static Control GetPreviewWith(object target)
|
|
{
|
|
Control rv;
|
|
Substitutes.TryGetValue(target, out rv);
|
|
return rv;
|
|
}
|
|
|
|
internal static void ApplyDesignerProperties(Control target, Control source)
|
|
{
|
|
if (source.IsSet(WidthProperty))
|
|
target.Width = source.GetValue(WidthProperty);
|
|
if (source.IsSet(HeightProperty))
|
|
target.Height = source.GetValue(HeightProperty);
|
|
if (source.IsSet(DataContextProperty))
|
|
target.DataContext = source.GetValue(DataContextProperty);
|
|
}
|
|
}
|
|
}
|
|
|