[Bug] [DrawingView] [UWP] Initial bind is not drawn and lines with single points are never drawn
zleao opened this issue · comments
José Pereira commented
Description
Found 2 bugs in the DrawingView for UWP (also found how to fix them)
- If we have lines bound to the control at creation time, these lines are not drawn
- 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
Steps to Reproduce
- Configure a DrawingView control with an input of a line with a single point (i.e. via binding)
- 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
- 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();
}
}
...
}
- 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));
}
...
}