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

Могу ли я сделать содержание расширитель colpased автоматически, когда некоторые другие элементы в ItemsControl является selcted

ответ

0

Вы можете заменить ItemsControl с ListBox связывают IsExpanded свойство Expander к IsSelected имущество 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}}" Таким образом, это сработало для меня Спасибо за помощь :) –