예제 #1
0
        public static XProperty CreateProperty <TThis, TValue>(
            string propertyName,
            bool affectsMeasure,
            Func <TPainter, TValue> defaultValueGet,
            Action <TPainter, TValue> propertySet,
            Action <TThis, TValue>?updateOtherProperty = null)
            where TThis : BaseView <TPainter, TContent>
        {
            var defaultValue = defaultValueGet(staticPainter);

            void PropertyChanged(TThis @this, object?newValue)
            {
                // We need to support nullable classes and structs, so we cannot forbid null here
                // So this use of the null-forgiving operator should be blamed on non-generic PropertyChanged handlers
                var @new = (TValue)newValue !;

                propertySet(@this.Painter, @new);
                updateOtherProperty?.Invoke(@this, @new);
                if (affectsMeasure)
                {
                    @this.InvalidateMeasure();
                }
                // Redraw immediately! No deferred drawing
#if Avalonia
                @this.InvalidateVisual();
            }

            var prop = XProperty.Register <TThis, TValue>(propertyName, defaultValue);
            global::Avalonia.AvaloniaObjectExtensions.AddClassHandler <TThis>(prop.Changed, (t, e) => PropertyChanged(t, e.NewValue));
            return(prop);
        }
예제 #2
0
        public static XProperty CreateProperty <TThis, TValue>(
            string propertyName,
            bool affectsMeasure,
            Func <TPainter, TValue> defaultValueGet,
            Action <TPainter, TValue> propertySet,
            Action <TThis, TValue>?updateOtherProperty = null)
            where TThis : BaseView <TPainter, TContent>
        {
            var defaultValue = defaultValueGet(staticPainter);

            void PropertyChanged(TThis @this, object newValue)
            {
                propertySet(@this.Painter, (TValue)newValue);
                updateOtherProperty?.Invoke(@this, (TValue)newValue);
                if (affectsMeasure)
                {
                    @this.InvalidateMeasure();
                }
                // Redraw immediately! No deferred drawing
#if Avalonia
                @this.InvalidateVisual();
            }

            var prop = XProperty.Register <TThis, TValue>(propertyName, defaultValue);
            global::Avalonia.AvaloniaObjectExtensions.AddClassHandler <TThis>(prop.Changed, (t, e) => PropertyChanged(t, e.NewValue));
            return(prop);
        }