Primary WPF APIs:
DependencyObject, DependencyPropertyDependencyProperty.Register, RegisterAttached, RegisterReadOnlyFrameworkPropertyMetadataPrimary Avalonia APIs:
AvaloniaObject, AvaloniaPropertyAvaloniaProperty.Register, RegisterAttached, RegisterDirectStyledProperty<T>, DirectProperty<TOwner, TValue>| WPF | Avalonia |
|---|---|
DependencyProperty |
AvaloniaProperty |
FrameworkPropertyMetadata |
property registration options + changed callbacks |
RegisterReadOnly |
DirectProperty with private setter backing field |
attached property via RegisterAttached |
attached property via AvaloniaProperty.RegisterAttached |
WPF C#:
public class HeaderCard : Control
{
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(
nameof(Title),
typeof(string),
typeof(HeaderCard),
new FrameworkPropertyMetadata(string.Empty));
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
}
Avalonia XAML usage:
<local:HeaderCard xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.Controls"
Title="Revenue" />
using Avalonia;
using Avalonia.Controls;
public class HeaderCard : Control
{
public static readonly StyledProperty<string> TitleProperty =
AvaloniaProperty.Register<HeaderCard, string>(nameof(Title), string.Empty);
public string Title
{
get => GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
}
Attached property pattern:
public static readonly AttachedProperty<bool> IsHighlightedProperty =
AvaloniaProperty.RegisterAttached<HeaderCard, Control, bool>("IsHighlighted");
StyledProperty and used in style selectors/setters.RegisterDirect with explicit getter/setter backing field pattern.