2011-04-06 61 views
0

我想讓listBox中的項目水平拉伸,但是如果item的內容大於listbox,則出現水平滾動條。如何避免這種情況?問題在列表框的DataTemplate中設置Horizo​​ntalAligment =「Stretch」

的XAML:

<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"> 
    <Window.Resources> 
     <DataTemplate x:Key="testTemplate"> 
      <Border x:Name="border" 
        BorderBrush="Black" 
        BorderThickness="1" 
        Margin="2" 
        Padding="2" 
        HorizontalAlignment="Stretch"> 
       <TextBlock Text="{Binding}" /> 
      </Border> 
     </DataTemplate> 
    </Window.Resources> 
    <Grid> 
     <ListBox x:Name="listBox" 
       VerticalAlignment="Stretch" 
       HorizontalAlignment="Stretch" 
       HorizontalContentAlignment="Stretch" 
       ItemTemplate="{StaticResource testTemplate}" /> 
    </Grid> 
</Window> 

回答

2

設置ScrollViewer.HorizontalScrollBarVisibilityDisabled

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
    ... 
</ListBox> 
相關問題