When declaring a property in WPF, you can set metadata like this
public static readonly DependencyProperty IsStopVisibleProperty =
DependencyProperty.Register("IsStopVisible", typeof(bool), typeof(MediaPlayer),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsParentArrange));
In Avalonia UI, there is no parameter to set metadata
public static readonly StyledProperty<bool> IsStopVisibleProperty =
AvaloniaProperty.Register<MediaPlayer, bool>(nameof(IsStopVisible), true);
What's the equivalent of FrameworkPropertyMetadataOptions.AffectsParentArrange ?
The simplest way to make a property affect the arrange of the control itself is to add a call to AffectsArrange
in your control's static constructor:
static MediaPlayer()
{
AffectsArrange(IsStopVisibleProperty);
}
However this is the equivalent of WPF's FrameworkPropertyMetadataOptions.AffectsArrange
flag, not AffectsParentArrange
. It is quite unusual for a control's property to directly affect the parent control's arrange - the scenario for AffectsParentArrange
is usually limited to attached properties on Panel
controls. Because of this, Avalonia's AffectsParentArrange
is a protected method on Panel
so will probably be unavailable in your control.
However if you're sure that you need to invalidate the parent's arrange on property change, probably the best way to do this would be to simply invalidate the parent arrange in OnPropertyChanged
:
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
if (change.Property == IsStopVisibleProperty)
{
((Control)Parent)?.InvalidateArrange();
}
base.OnPropertyChanged(change);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.