Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.
- Add reference to
jp2masa.Avalonia.PropertyGenerator.CSharp
package:
<PackageReference Include="jp2masa.Avalonia.PropertyGenerator.CSharp" Version="0.10.0-beta2" PrivateAssets="All" />
- Declare Avalonia properties as usual, except the CLR members, which are now automatically generated!
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
namespace Avalonia.PropertyGenerator.CSharp.Demo
{
internal sealed partial class DemoControl : TemplatedControl
{
public static readonly StyledProperty<double> NumberProperty =
AvaloniaProperty.Register<DemoControl, double>(nameof(Number));
[BackingField(Name = "m_text", Accessibility = BackingFieldAccessibility.Internal)]
public static readonly DirectProperty<DemoControl, string?> TextProperty =
AvaloniaProperty.RegisterDirect<DemoControl, string?>(nameof(Text), o => o.Text, (o, v) => o.Text = v);
public static readonly AttachedProperty<bool> BoolProperty =
AvaloniaProperty.RegisterAttached<DemoControl, Control, bool>("Bool");
public DemoControl()
{
m_text = "Hello World!";
}
}
}
namespace Avalonia.PropertyGenerator.CSharp.Demo
{
partial class DemoControl
{
public double Number
{
get => GetValue(NumberProperty);
set => SetValue(NumberProperty, value);
}
internal string? m_text;
public string? Text
{
get => m_text;
set => SetAndRaise(TextProperty, ref m_text, value);
}
public static bool GetBool(Avalonia.AvaloniaObject obj) => obj.GetValue(BoolProperty);
public static void SetBool(Avalonia.AvaloniaObject obj, bool value) => obj.SetValue(BoolProperty, value);
}
}
- Readonly direct properties
- Generate XML documentation