1

I am trying to pass a variable into my GraphicsView canvas, but it looks like I have some problems receiving the passed variable in my drawable.

What am I doing wrong?

Drawable

public class NewDrawable : IDrawable
{

    public float Vectors { get; set; }

    public static BindableProperty VectorsProperty = BindableProperty.Create(nameof(Vectors), typeof(float), typeof(NewDrawable));


    public void Draw(ICanvas canvas, RectF dirtyRect)
    {


        canvas.StrokeColor = Color.FromRgba("ebc500");
        canvas.StrokeSize = 15;
        canvas.StrokeLineCap = LineCap.Round;
        canvas.DrawArc(40, 40, 200, 200, 90, Vectors, true, false);

View

            <GraphicsView x:Name="newDrawableView">
                <GraphicsView.Drawable>
                    <drawables:NewDrawable Vectors="{Binding TotalProcent}" />
                </GraphicsView.Drawable>
            </GraphicsView>

ViewModel

        [ObservableProperty]
        public float totalProcent;

The variable should be passed to my drawable

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196

1 Answers1

0

Look at code snippet in Bindable Properties / Create Accessors.

Property Vectors is missing get/set code that uses VectorsProperty, to tell XAML what is happening:

public float Vectors
{
    get => (float)GetValue(VectorsProperty);
    set => SetValue(VectorsProperty, value);
}

To use GetValue

From Bindable Properties / Create a property:

To create a BindableProperty instance, the containing class must derive from the BindableObject class. However, the BindableObject class is high in the class hierarchy, so the majority of classes used for UI functionality support bindable properties.

Have your custom class inherit from BindableObject:

public class NewDrawable : BindableObject, IDrawable
ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196