I am currently creating a program that dynamically adds Image to a dockPanel every time a user presses a button. I was wondering how I could get it so that every time the user adds another image to the dockPanel the images shrink so that they are both the same size and fit inside the dockPanel.
Here is my current code:
Uri myUri = new Uri(@"C:\Users\Jim\Desktop\Project\bin\Debug\pic.bmp", UriKind.RelativeOrAbsolute);
BmpBitmapDecoder decoder2 = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource2 = decoder2.Frames[0];
// Draw the Image
Image myImage2 = new Image();
myImage2.Source = bitmapSource2;
myImage2.Stretch = Stretch.None;
myImage2.Margin = new Thickness(20);
dockPanel1.Children.Add(myImage2);
I tried doing myImage2.Height=80 and myImage2.Width=40 (thinking that it would change the size through percentage but it didn’t seem to work this way.
Any Ideas?
Thanks
I think you’d be better served by using a different container, specifically the
UniformGridcontainer will do exactly what you want.Here’s a good tutorial: http://www.wpftutorials.com/2011/03/wpf-uniformgrid.html
UPDATE
UniformGrid may not be in the toolbox, but it is a built-in primitive so you do have it.