I’m encoutering a wierd issue.
I’m applying an image to a grid, and it cuts through the image by screen reolution, and not logiclly.
At 1280 x 800 it shows like this:

and when it’s 800 x 600 it shows like this:

Which is kinda messed up because with lower height resolution, it shows more of the picture.
Any idea why the hell that’s happening?
this is my code :
Grid MyGrid = new Grid();
Image img = new Image();
StackPanel myStackPanel = new StackPanel();
myStackPanel.CanVerticallyScroll = true;
Image myImage = new Image();
BitmapImage myImageSource = new BitmapImage();
myImageSource.BeginInit();
myImageSource.UriSource = new Uri("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
myImageSource.EndInit();
myImage.Source = myImageSource;
// myImage.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
// myImage.VerticalAlignment = System.Windows.VerticalAlignment.Center;
// myStackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
// myStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
myStackPanel.Children.Add(myImage);
MyGrid.Children.Add(myStackPanel);
_LayoutRoot.Children.Add(MyGrid);
The problem:
Don’t use a
StackPanelif you want the image resized properly (why is there a StackPanel anyway if it contains nothing else?), here it will just overflow and cut. There are various other panels, e.g.Grids, which are better suited for this.