xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] [DrawingView] [UWP] Initial bind is not drawn and lines with single points are never drawn

zleao opened this issue · comments

Description

Found 2 bugs in the DrawingView for UWP (also found how to fix them)

  1. If we have lines bound to the control at creation time, these lines are not drawn
  2. Line with single points are never drawn. I guess there's some issue in the UWP.InkCanvas when drawing single points.

Link to Reproduction Sample

Sample

Steps to Reproduce

  1. Configure a DrawingView control with an input of a line with a single point (i.e. via binding)
  2. Execute the app

Expected Behavior

The initial Lines and SinglePoints should be drawn when the control is created

Actual Behavior

Nothing is drawn. The canvas remains empty

Basic Information

  • Version with issue: 2.0.5
  • Last known good version: N/A
  • IDE: VS2022 17.3.6
  • Platform Target Frameworks:
    • UWP: 19041
  • Nuget Packages:
    • Xamarin.CommunityToolkit v2.0.5
    • Xamarin.Forms v5.0.0.2515
    • Xamarin.Essentials v1.7.3

Workaround

  1. For the initial lines loading, edit the UWP renderer to force a LoadLines at creation time, if there are lines to draw:
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.CommunityToolkit.UI.Views.DrawingView> e)
{
    ...
    if (Control == null && Element != null)
    {
        ...
        //FIX1: Force a LoadLines, if there are Lines available at creation time
        if (Element.Lines.Count > 0)
        {
            LoadLines();
        }
    }
    ...
}
  1. For the Singlepoint drawing, in the method LoadLines of the UWP renderer, when dealing with a single point line, add a second point with the same coordinates as the first:
foreach (var line in lines)
{
    ...

    if (stylusPoints.Count == 1)
    {
        stylusPoints.Add(new Windows.Foundation.Point(stylusPoints[0].X, stylusPoints[0].Y));
    }
    ...
}

Reproduction imagery

image