2012-04-05 12 views
0

MSDNの例を示します。DataTemplateの幅をリストボックスの幅に設定するにはどうすればよいですか?

<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

Whell、それが起こったとして本当のbroblemは、リストボックスが、エキスパンダーのヘッダーではなかったです。 =(http://joshsmithonwpf.wordpress.com/2007/02/24/stretching-content-in-an-expander-header/ –

関連する問題