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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WPF
  4. Set the margin for Listbox

Set the margin for Listbox

Scheduled Pinned Locked Moved WPF
wpfhelp
2 Posts 2 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.
  • M Offline
    M Offline
    member27
    wrote on last edited by
    #1

    Hi all, I want to create twolist box ,one in left side and other in right side in runtime.I wrote one code but i cant set the correct margin can any one help me.. here is my source code.. in xaml code: <StackPanel x:Name="stkPnlCaption" Orientation="Vertical" Height="500" Width="800"> </StackPanel> in xaml.cs:: ListBox list = new ListBox(); list.Width = 200; list.Height = 200; list.Margin = new Thickness(148, 131, 0, 131); list.HorizontalAlignment = HorizontalAlignment.Left ; list.VerticalAlignment = VerticalAlignment .Top ; stkPnlCaption.Children.Add(list); CheckBox checkBox = new CheckBox(); checkBox.Content = "Yes" ; list.Items.Add(checkBox); ListBox list1 = new ListBox(); list1.Width = 200; list1.Height = 200; list1.Margin = new Thickness(298, 131, 280, 131); list1.HorizontalAlignment = HorizontalAlignment.Right; list1.VerticalAlignment = VerticalAlignment.Top; stkPnlCaption.Children.Add(list1); CheckBox checkBox1 = new CheckBox(); checkBox1.Content = "Yes" ; list1.Items.Add(checkBox1); i want the both the list box in same height and width ..one in left side and other in right side(paralley).

    P 1 Reply Last reply
    0
    • M member27

      Hi all, I want to create twolist box ,one in left side and other in right side in runtime.I wrote one code but i cant set the correct margin can any one help me.. here is my source code.. in xaml code: <StackPanel x:Name="stkPnlCaption" Orientation="Vertical" Height="500" Width="800"> </StackPanel> in xaml.cs:: ListBox list = new ListBox(); list.Width = 200; list.Height = 200; list.Margin = new Thickness(148, 131, 0, 131); list.HorizontalAlignment = HorizontalAlignment.Left ; list.VerticalAlignment = VerticalAlignment .Top ; stkPnlCaption.Children.Add(list); CheckBox checkBox = new CheckBox(); checkBox.Content = "Yes" ; list.Items.Add(checkBox); ListBox list1 = new ListBox(); list1.Width = 200; list1.Height = 200; list1.Margin = new Thickness(298, 131, 280, 131); list1.HorizontalAlignment = HorizontalAlignment.Right; list1.VerticalAlignment = VerticalAlignment.Top; stkPnlCaption.Children.Add(list1); CheckBox checkBox1 = new CheckBox(); checkBox1.Content = "Yes" ; list1.Items.Add(checkBox1); i want the both the list box in same height and width ..one in left side and other in right side(paralley).

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      An easier way to do this is to use a Grid with two columns, both of which are the same size. Don't set any size info in your listboxes, just assign them to the appropriate grid column and let the grid take care of laying your items out.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      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