2014-09-19 134 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