2014-09-19 135 views
1

我在ItemsControl中顯示了一個擴展器項目列表,並將項目列表綁定到它。 我下面的XAML結構是ItemsControl中的摺疊擴展器WPF

<ItemsControl ItemsSource="{Binding}" >    
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Expander ExpandDirection="Down" Style="{StaticResource ResourceKey=ExpanderItemStyle}" > 
       <Expander.Header> 
        <BulletDecorator> 
        //Expander header by default its collapsed 
        <Label Style="{StaticResource ResourceKey=ChapterHeadStyle}" Content="{Binding name}"></Label>           
        </BulletDecorator> 
       </Expander.Header> 
       <StackPanel> // Expander body want to collapse it when some some other items of ItemsControl is expanded 
       </StackPanel> 
      </Expander> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

我可以當ItemsControl中的其他一些項目被selcted

回答

0

您可以ListBox一個綁定的ExpanderIsSelectedIsExpanded財產更換ItemsControl擴展內容自動colpased財產ListBoxItem。 (請參閱http://social.msdn.microsoft.com/Forums/vstudio/en-US/a2988ae8-e7b8-4a62-a34f-b851aaf13886/windows-presentation-foundation-faq?forum=wpf#expander_list

您還可以將IsExpanded綁定到某個viewmodel屬性並從該屬性中取出。通過wpf行爲可以實現相同的結果。

要回答你的問題:不,沒有「自動」方式來摺疊其他擴展器。

+0

IsExpanded =「{Binding Mode = TwoWay,Path = IsSelected,RelativeSource = {RelativeSource AncestorType = ListBoxItem,Mode = FindAncestor}}」這種方式對我很有幫助感謝您的幫助:) – 2014-09-19 06:52:00