Description
The drawn image can also be visible outside the canvas
Windows.mp4
Android.mp4
Steps to Reproduce
Page.xaml
<?xml version =" 1.0" encoding =" utf-8" ?>
<ContentPage x : Class =" Happy.MainPage"
xmlns =" http://schemas.microsoft.com/dotnet/2021/maui"
xmlns : x =" http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor =" White" >
<Grid >
<Grid BackgroundColor =" #1a2033"
HeightRequest =" 300"
VerticalOptions =" Center" >
<GraphicsView x : Name =" graphicsView" />
</Grid >
</Grid >
</ContentPage >
Page.cs
public partial class MainPage : ContentPage
{
private readonly PDrawable drawable = new ( ) ;
public MainPage ( )
{
InitializeComponent ( ) ;
graphicsView . Drawable = drawable ;
graphicsView . StartInteraction += GraphicsView_StartInteraction ;
graphicsView . DragInteraction += GraphicsView_DragInteraction ;
}
private float oldX , oldY ;
private void GraphicsView_DragInteraction ( object ? sender , TouchEventArgs e )
{
var x = e . Touches [ 0 ] . X ;
var y = e . Touches [ 0 ] . Y ;
x -= oldX ;
y -= oldY ;
drawable . X += x ;
drawable . Y += y ;
oldX = e . Touches [ 0 ] . X ;
oldY = e . Touches [ 0 ] . Y ;
graphicsView . Invalidate ( ) ;
}
private void GraphicsView_StartInteraction ( object ? sender , TouchEventArgs e )
{
oldX = e . Touches [ 0 ] . X ;
oldY = e . Touches [ 0 ] . Y ;
}
}
PDrawable.cs
internal class PDrawable : IDrawable
{
public float X { get ; set ; } = 20f ;
public float Y { get ; set ; } = 20f ;
public void Draw ( ICanvas canvas , RectF dirtyRect )
{
canvas . SaveState ( ) ;
canvas . FillColor = Colors . Coral ;
canvas . FillEllipse ( X , Y , 100 , 100 ) ;
canvas . ResetState ( ) ;
}
}
Link to public reproduction project repository
No response
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android8.0~14.0
Did you find any workaround?
#if ANDROID
graphicsView . PropertyChanged += ( s , e ) =>
{
if ( e . PropertyName == nameof ( Width ) || e . PropertyName == nameof ( Height ) )
{
if ( s is GraphicsView gView )
{
if ( gView . Width > 0 && gView . Height > 0 )
{
gView . Clip = new RectangleGeometry ( new Rect ( )
{
X = 0 ,
Y = 0 ,
Width = gView . Width ,
Height = gView . Height
} ) ;
}
}
}
} ;
#end
Relevant log output
No response
Description
The drawn image can also be visible outside the canvas
Windows.mp4
Android.mp4
Steps to Reproduce
Page.xaml
Page.cs
PDrawable.cs
Link to public reproduction project repository
No response
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android8.0~14.0
Did you find any workaround?
Relevant log output
No response