<ScrollViewer x:Name="dataScroller" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto"> <ListBox Name="mylistbox" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="50" SelectionChanged="Mylistbox_SelectionChanged" /> </ScrollViewer> <Label Name="label1" Content="Label" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="28,13,0,0" Width="92" Height="23" />
public Window1() { InitializeComponent(); this.WindowState= WindowState.Maximized; List<string> mylist=new List<string> (); for(int i=0;i<=50;i++) { mylist.Add(" item" + i); } mylistbox.ItemsSource=mylist; } void Mylistbox_SelectionChanged(object sender, SelectionChangedEventArgs e) { label1.Content=mylistbox.SelectedItem.ToString(); }
Why do you use the Height property of the ListBox?
Height
ListBox
If you want to scroll the whole of the ListBox's content with the outer ScrollViewer, omit the Height property of the wrapped ListBox.
ScrollViewer
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)