wpf - In a horizontal listbox how do I align items to the top? -


How can I align objects on top in a horizontal listbox?

I have participated out of ideas to touch the vertical alignment = "top".

  & lt; Window Resource & gt; & Lt; DataTimeplate DataType = "{x: Type l: MyType}" & gt; & Lt; Grid Vertical Alignment = "Top" & gt; & Lt; Text Block Vertical Element = "Top" Text = "{Binding MyView}" Background = "Yellow" /> & Lt; / Grid & gt; & Lt; / DataTemplate & gt; & Lt; /Window.Resources> & Lt; Grid & gt; & Lt; List Box Name = "List Box" Item Source = "{Binding}" Vertical Alignment = "Top" & gt; & Lt; ListBox.ItemsPanel & gt; & Lt; ItemsPanelTemplate & gt; & Lt; StackPanel Orientation = "Horizontal" vertical alignment = "top" /> & Lt; / ItemsPanelTemplate & gt; & Lt; /ListBox.ItemsPanel> & Lt; ListBox.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; ListBoxItem content = "{binding}" vertical alignment = "top" vertical content element = "top" /> & Lt; / DataTemplate & gt; & Lt; /ListBox.ItemTemplate> & Lt; / ListBox & gt; & Lt; / Grid & gt;  

  Using the system. Namespace WpfApplication5 {Public Partial Segment Window 1: Window {Public Window 1 () {InitializeComponent (); This.listBox.ItemsSource = New MyType [] {New MyType {MyValue = "Long \ nItem"}, New MyType {MyValue = "I want to align it on top"}}; }} Public class MyType {public string MyValue {get; Set; }}}}  

You have to set the vertical content element on the list box, all others The alignments you have, they can be removed once properly.

  ....  List Box Name = "List Box" Item Source = "{Binding}" Vertical Content Element = "Top" & gt; ....  

The default 'center' for vertical content alignment on your list box, even if you were setting vertical alignments elsewhere, it was only aligned at the top of the list box item , Which were still streched or rather focused on top if you set the vertical content alignment to Stretch, then you will see other vertical alignment = "top" announcements.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -