Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF application which is going to display a number of images in a slideshow.

The image height should be fixed and the aspect ratio remain the same.
If the width of the image is therefore too large it should keep the width gained from the height resize and start the position of the image at the furthest left point (in view) and then scroll left to right sing animation till it reaches the other end.

I am not sure how to setup the image control so the width can stretch outside the bounds of its parent control or how to setup the animations required.

Anyone know of anywhere to start, ideas or links are appreciated.
Posted

You need to set binding. This code will make your picture to fit height and width of your source element.
C#
var _img = new Image { Stretch = Stretch.Fill, StretchDirection = StretchDirection.Both };

           
var height = new Binding("ActualHeight") {Source = yourSource };
var width = new Binding("ActualWidth") { Source = yourSource};

_img.SetBinding(FrameworkElement.WidthProperty, width);
_img.SetBinding(FrameworkElement.HeightProperty, height);          


Hope this helped you
 
Share this answer
 
Check out this video, very good (and short) explanation of resizing images in controls.
http://www.youtube.com/watch?v=7LgtNW3HJCU[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900