0

Moving the app under wpf to avalonia ui. During the transfer, I encountered something that is not in the documentation. In General there is a piece of code from wpf:

public class BaseLabelElement : UIElement
{
    public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
        "FontFamily", typeof(FontFamily), typeof(BaseLabelElement), new FrameworkPropertyMetadata(DefaultFontFamily,
            FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, FontFamilyPropertyChanged));

    public FontFamily FontFamily
    {
        get { return (FontFamily)GetValue(FontFamilyProperty); }
        set { SetValue(FontFamilyProperty, value); }
    }
}

How to add a new behavior corresponding to

new FrameworkPropertyMetadata (.., FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,..)

for the dependency property in Avalonia?

4

1 回答 1

0

AffectsRender<T>(AvaloniaProperty[]) and AffectsMeasure<T>(AvaloniaProperty[])Visual 类中的方法。这些方法应该在静态控件构造函数中调用,每个控件属性在修改时都会导致重绘。这类似于 WPF 中的 FrameworkPropertyMetadata.AffectsRender 和 AffectsMeasure 标志。

于 2020-07-30T13:18:53.760 回答