Search
Wednesday, November 26, 2014 ..:: Home ::.. Register  Login
   Calendar  
     
  
   Search  
     
  
   Blogroll  
     
  
   Disclosure  
All blog entries are the opinions of the author and do not necessarily reflect the opinions of their employer. All the code presented is for explanation and demonstration purposes only. Any damages incurred to your site and/or data are not the responsibility of the author. Every effort is taken to ensure the code properly compiles, however sometimes there are some hiccups and you might be required to do your own debugging.
     
  
   TechTidBits (Blog)  

My ListBox items WILL NOT stretch to maximum widths? WHY NOT?!

Nov 2

Written by:
Wednesday, November 02, 2011 10:24 PM  RssIcon

imageAre you trying to make your items in your ListBox stretch out to the maximum width of your container?  And it’s JUST NOT WORKING for you?  I have two things you might try (and hopefully one will work).

For the last couple of nights, I’ve been FIGHTING with my WP7 DevTeach Ottawa 2011 app to show Presenters “nicely.”  Ok, ok, so I’m NOT a graphic designer, but I think my UI works and looks nice.  But I’m fighting with forcing the content of my ListBox items to be the maximum width of the container.  Here’s what I’m talking about.

image

Do you see the spaces on the far right?  Doesn’t look very nice, ugly in my opinion actually!  And I DID set the contents to a Grid, set the 2nd column width to be the Star (XAMLs way of saying 100%), blah blah blah…….I DID all of that standard stuff!  But I still get the ugly looking thing above!

Turns out I’m not the only one.  I asked Laurent Duveau about this, and he quickly replied with trying to set the HorizontalContentAlignment = “Stretch”.  hhhmm he’s seen this, done that and figured out possible solution.

image

Unfortunately this didn’t solve my problem...well, not exactly!  The thing about MVPs is, sometimes, if they don’t give you the right answer, they DO give you enough to go FIND the answer!  Which is exactly what I did!  I found another link which helped me fix my problem via a different mechanism, using the ListBox.ItemContainerStyle within the ListBox.  (sorry for the lack of xaml/xml to cut’n’paste, but my blog engine doesn’t like those chevrons)

image

 

Hey, if you’re like me, hhhmmmmm that xaml is nice, but uuuhhh PROVE IT!  Ok!

image

Notice, how all the presenters profiles are lining up properly on the right?!  COOL!  THAT’S what I was looking for!  Merci Laurent pour ton aide!

Now that I got THAT width thing figured out, it’s time to grab a coffee and get coding!

 

 

Resources

Laurent Duveau: http://weblogs.asp.net/lduveau/

logo

PCHenry.com: I just released my fourth WP7 app tonight! YAHOO! DevTeach Ottawa 2011

Nilesh Gule’s Technical Blog: NGTweet Part3: Use Silverlight Themes to enhance UI (search for ‘stretch’ on thi spage).

stackoverflow: Silverlight 3: ListBox DataTemplate HorizontalAlignment

stackoverflow: How to get a ListBox ItemTemplate to stretch horizontally to full width of the ListBox?

Tags:
Categories:
Location: Blogs Parent Separator TechTidBits

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
     
  
Copyright 1999-2012 by PCHenry.com   Terms Of Use  Privacy Statement