2012-09-03 26 views
0

我有擴展器項目的Listbox並希望它們填充整個可用的水平空間。設置擴展器的寬度以填充可用空間

這裏是一個小例子

<Window x:Class="ExpanderTest.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> 
    <ListBox> 
     <ListBoxItem> 
      <Expander Background="Tan" 
         HorizontalAlignment="Left" Header="My Expander" 
         ExpandDirection="Down" IsExpanded="True"> 
       <TextBlock TextWrapping="Wrap"> 
        Lorem ipsum dolor sit amet, consectetur 
        adipisicing elit, sed do eiusmod tempor incididunt ut 
        labore et dolore magna aliqua 
       </TextBlock> 
      </Expander> 
     </ListBoxItem> 
    </ListBox> 
</Grid> 

如果我在expander設置Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualWidth}",它的行爲幾乎一樣我想它,除了擴展是有點太寬。

xaml有沒有辦法告訴ListBoxItemExpander填充所有可用的水平空間?

(如果寬度變小,在HIGHT應該得到更大的相應顯示全部內容)

回答

3

好吧,我找到了解決辦法,只需添加

ScrollViewer.HorizontalScrollBarVisibility="Disabled" 

到ListBox。

相關問題