Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Image control not getting resized while resizing window

Image control not getting resized while resizing window

Scheduled Pinned Locked Moved WPF
csharpwpfdata-structures
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DavJes
    wrote on last edited by
    #1

    Hi , I have a WPF - window, contains a StackPanel (designed in xmal, where height and width are Auto = 0). In code reading an image folder and adding the files to stackPanel. While adding files to image control, created a border object and intern created the image object and fina tlly adding the border to stackpanel. Now when i try to resize the window, the stackpanel stays same size , as the image control width and hight are fixed thou the stackpanel is auto size. below is the code snip , //after reading the image files, add it to stack panel foreach (string strFile in ArrStrFiles) { // display the file names here BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.UriSource = new Uri(strFile); bi.EndInit(); Image img = new Image(); img.Source = bi; img.Width = 170; img.Height = stkPanl.ActualHeight; img.Stretch = Stretch.Fill; img.HorizontalAlignment = HorizontalAlignment.Stretch; img.VerticalAlignment = VerticalAlignment.Stretch; Border border = new Border(); border.Background = new SolidColorBrush(Colors.Black); border.BorderThickness = new Thickness(5); border.BorderBrush = new SolidColorBrush(Colors.Black); border.Child = img; stkPanl.Children.Add(border); } xmal : Plz let me know how we can resize the stackPanel when the image is added thru code. thanks

    D 1 Reply Last reply
    0
    • D DavJes

      Hi , I have a WPF - window, contains a StackPanel (designed in xmal, where height and width are Auto = 0). In code reading an image folder and adding the files to stackPanel. While adding files to image control, created a border object and intern created the image object and fina tlly adding the border to stackpanel. Now when i try to resize the window, the stackpanel stays same size , as the image control width and hight are fixed thou the stackpanel is auto size. below is the code snip , //after reading the image files, add it to stack panel foreach (string strFile in ArrStrFiles) { // display the file names here BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.UriSource = new Uri(strFile); bi.EndInit(); Image img = new Image(); img.Source = bi; img.Width = 170; img.Height = stkPanl.ActualHeight; img.Stretch = Stretch.Fill; img.HorizontalAlignment = HorizontalAlignment.Stretch; img.VerticalAlignment = VerticalAlignment.Stretch; Border border = new Border(); border.Background = new SolidColorBrush(Colors.Black); border.BorderThickness = new Thickness(5); border.BorderBrush = new SolidColorBrush(Colors.Black); border.Child = img; stkPanl.Children.Add(border); } xmal : Plz let me know how we can resize the stackPanel when the image is added thru code. thanks

      D Offline
      D Offline
      DavJes
      wrote on last edited by
      #2

      Xmal Part missed : ..

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups