I have a custom canvas in an application, which is not showing image, in XAML, i write:
<local:MyCanvas>
<local:MyCanvas.LayoutTransform>
<ScaleTransform x:Name="scale" ScaleX="1" ScaleY="1" />
</local:MyCanvas.LayoutTransform>
<Image Source="C:\abc.jpg" />
</local:MyCanvas>
I have tried it on Canvas, and it works, but in the derived class, it doesn’t appear, but Visual Studio shows the outline meaning image has been added.
As an alternative, inside MyCanvas:Canvas class, i type:
Image img = new Image();
img.Width = 200;
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\abc.jpg");
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
img.Source = myBitmapImage;
this.Children.Add(img);
Still not visible. Any ideas?
I have been experimenting with different things and I have been able to add the image by enclosing it in a DrawingVisual, here is the code:
And by then adding the DrawingVisual to the custom Canvas, here is the code:
Using this method, the image is visible, and it is working fine.
But why isn’t it adding to MyCanvas using the previous method?