Покажите ваш XAML код и код заполнения ListBox'a ?
Если просто разместить ListBox в гриде и в окне, то он по-умолчанию будет растянут и полосы прокрутки будут появляться и по горизонтали и по вертикали. Например так:
Код | <Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" > <Grid> <Border BorderBrush="LightCoral" BorderThickness="1"> <ListBox x:Name="_listBox"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" Background="Bisque" Margin="5"/> <TextBlock Text="{Binding Description}" Background="LightCyan" Margin="5"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Border> </Grid> </Window>
|
Код | public partial class MainWindow : Window { public MainWindow() { InitializeComponent();
_listBox.Items.Add(new Item {Name = "John Rembo", Description = "Tra-ta-ta-ta-ta"}); _listBox.Items.Add(new Item {Name = "Ricky Martin", Description = "lalalalala"}); _listBox.Items.Add(new Item {Name = "another person", Description = "nevermind"}); _listBox.Items.Add(new Item { Name = "another person", Description = "nevermind" }); _listBox.Items.Add(new Item { Name = "another person", Description = "nevermind" }); _listBox.Items.Add(new Item { Name = "another person", Description = "nevermind" }); _listBox.Items.Add(new Item { Name = "another person", Description = "nevermind" }); _listBox.Items.Add(new Item { Name = "another person", Description = "nevermind" }); } }
public class Item { public string Name { get; set; } public string Description { get; set; } }
|
|