I am choosing image using PhotoChooserTask.
I am trying to load selected image on canvas but not able to load.
Here is my code
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
Image image = new Image();
string path = e.OriginalFileName;
Uri uri = new Uri(path, UriKind.Relative);
ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
image.Height = paint.Height;
image.Width = paint.Width;
image.SetValue(Image.SourceProperty, img);
Canvas.SetLeft(image, 50);
Canvas.SetTop(image, 50);
paint.Children.Add(image);
}
}
MainPage.xaml
<Canvas x:Name="paint" Background="Transparent" Margin="0,95,0,139" >
</Canvas>
I am getting why this is not working. Is there any change in my code?
Added my comment as an answer as I’m pretty sure this is the problem.
Should you be setting the position of the image in the canvas via the
Canvas.LeftandCanvas.Topattributes? Eg.