Найдено несколько свойств с именем «BadgeView.Shared.CircleView.CornerRadius» - исключение - PullRequest
0 голосов
/ 18 марта 2019

Я использую BadgeView плагин в Xamarin.Forms с TitleView, но получаю исключение

Xamarin.Forms.Xaml.XamlParseException: позиция 8:81. множественный найдены свойства с именем 'BadgeView.Shared.CircleView.CornerRadius'.

Это мой код

<NavigationPage.TitleView>
    <StackLayout Orientation="Horizontal" VerticalOptions="End" Spacing="10">
    <Image Source="bell.png" HorizontalOptions="Center" VerticalOptions="Center"></Image>
    <badge:BadgeView Text="2" BadgeColor="Yellow" VerticalOptions="End" HorizontalOptions="Start"></badge:BadgeView>
    </StackLayout>
</NavigationPage.TitleView>

1 Ответ

0 голосов
/ 18 марта 2019

Это ошибка в плагине, которая отмечена в разделе вопросов в плагине Github

И есть обходной путь, который добавил один парень, но я не уверен, что этобудет работать для вас, как показано здесь то, что он сделал, было

CircleView.cs

Примечание: закомментируйте свойство CornerRadius.

    public class CircleView : BoxView
{
    //public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(CircleView), 0.0);
    //public double CornerRadius
    //{
    //    get { return (double)GetValue(CornerRadiusProperty); }
    //    set { SetValue(CornerRadiusProperty, value); }
    //}
}

Для Android:

CircleViewRenderer.cs

Примечание. Добавлено жестко заданное значение для CornerRadius (16)

public class CircleViewRenderer : BoxRenderer
{
    private float _cornerRadius;
    private RectF _bounds;
    private Path _path;
    public CircleViewRenderer(Context context)
       : base(context)
    {
    }
    public static void Initialize() { }
    protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
    {
        base.OnElementChanged(e);

        if (Element == null)
        {
            return;
        }
        var element = (CircleView)Element;

        _cornerRadius = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float)16, Context.Resources.DisplayMetrics);

    }

    protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
    {
        base.OnSizeChanged(w, h, oldw, oldh);
        if (w != oldw && h != oldh)
        {
            _bounds = new RectF(0, 0, w, h);
        }

        _path = new Path();
        _path.Reset();
        _path.AddRoundRect(_bounds, _cornerRadius, _cornerRadius, Path.Direction.Cw);
        _path.Close();
    }

    public override void Draw(Canvas canvas)
    {
        canvas.Save();
        canvas.ClipPath(_path);
        base.Draw(canvas);
        canvas.Restore();
    }
}

Для iOS: CircleViewRenderer.cs Примечание. Добавленное жестко закодированное значение для CornerRadius (16) кода iOS еще не проверено.

public class CircleViewRenderer : BoxRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
   {
       base.OnElementChanged(e);

       if (Element == null)
           return;

       Layer.MasksToBounds = true;
       //Layer.CornerRadius = (float)((CircleView)Element).CornerRadius / 2.0f;
       Layer.CornerRadius = (float)(16) / 2.0f;
   }
}
...