Reputation: 502
After looking for the answer in both Microsoft documentation and forums, I am at a loss. I am loading a png image as a background for an inkCanvas (WPF) which works fine, however, it always resizes the image to fit in the canvas, despite the image size..
Here was my last attempt with no success:
BitmapImage ii = new BitmapImage(new Uri(path));
Image img = new Image();
img.Stretch = Stretch.None;
img.Source = ii;
InkCanvas1.Background = new ImageBrush(ii);
Here is what it looks like using Stretch.None and Stretch.Fill
Here is what I am trying to achieve:
Can this be done?
Upvotes: 0
Views: 1031
Reputation: 24453
The problem is that you're trying to set properties on an Image
object that you're not using while ignoring the same settings on the ImageBrush
that you are using. The Image
in this case is just being thrown away and the ImageBrush
just happens to be using the same source image. Set the Stretch
property on the ImageBrush
instead:
BitmapImage ii = new BitmapImage(new Uri(path));
ImageBrush imageBrush = new ImageBrush(ii);
imageBrush.Stretch = Stretch.Uniform;
InkCanvas1.Background = imageBrush;
Upvotes: 2