namespace Images_and_Borders{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Grid grid = new Grid(); Image image = new Image(); BitmapImage bitmap = new BitmapImage(new Uri("d:\\image.jpg")); Border imageBorder = new Border(); double aspectRatio = 0; image.Source = bitmap; aspectRatio = image.Width / image.Height; imageBorder.Height = 200; imageBorder.Width = imageBorder.Height * aspectRatio; imageBorder.Child = image; grid.Children.Add(imageBorder); } }}