2012-04-05 113 views
0

下面是MSDN的示例。如何將DataTemplate的寬度設置爲Listbox的寬度?

<GroupStyle> 
    <GroupStyle.ContainerStyle> 
    <Style TargetType="{x:Type GroupItem}"> 
     <Setter Property="Margin" Value="0,0,0,5"/> 
     <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type GroupItem}"> 
      <Expander IsExpanded="True" BorderBrush="#FFA4B97F" 
         BorderThickness="0,0,0,1"> 
       <Expander.Header> 
       <DockPanel> 
        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" 
          Margin="5,0,0,0" Width="100"/> 
        <TextBlock FontWeight="Bold" 
          Text="{Binding Path=ItemCount}"/> 
       </DockPanel> 
       </Expander.Header> 
       <Expander.Content> 
       <ItemsPresenter /> 
       </Expander.Content> 
      </Expander> 
      </ControlTemplate> 
     </Setter.Value> 
     </Setter> 
    </Style> 
    </GroupStyle.ContainerStyle> 
</GroupStyle> 

如何讓它佔據整個列表框的寬度? (Horizo​​ntalScrollBar被禁用)? 我確實需要的是DockPanel被拉伸。

回答

1

您必須在您的項目中包含PresentationFramework.Aero的參考。 這在你的列表框後,必須插入此屬性:

<ListBox 
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
    HorizontalContentAlignment="Stretch" 
> 
</ListBox> 
+0

線輪,因爲它發生了真正的broblem不符合列表框,但在膨脹的頭。 =(http://joshsmithonwpf.wordpress.com/2007/02/24/stretching-content-in-an-expander-header/ – 2012-04-05 14:41:18

相關問題