У меня есть CollectionViewSource
, связанный с ObservableCollection
моего ViewModels
. Затем у меня есть style
на GroupItem
, у которого есть expander
. Я хочу иметь возможность «свернуть все» и «развернуть все» в заголовках групп, но у меня проблемы с привязкой к isExpanded
на expander
в ControlTemplate
. У меня есть этот код:Связывание с CollectionViewSource с расширительным стилем
<Style x:Key="GroupStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="{Binding Path=**????**}" Template="{StaticResource DAExpander}">
<Expander.Header>
<DockPanel VerticalAlignment="Center">
<Image DockPanel.Dock="Left" x:Name="scItemIcon" Source="./groupIcon.ico" Height="18" Width="18"/>
<TextBlock DockPanel.Dock="Left" Text="{Binding Name}" VerticalAlignment="Center" Margin="4,0,6,0" />
</DockPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
У меня есть свойство IsExpanded на мой взгляд модели, но я не могу понять, как получить к нему доступ. Я нашел такие примеры, как:
<Expander IsExpanded="{Binding Path=Items[0].IsExpanded}"
<Expander IsExpanded="{Binding Path=Name.IsExpanded}"
Ничего из этого не работает. Есть ли способ сделать это или мне нужно использовать другой подход?
Edit: более XAML, а также просматривать код модели:
<ListBox ItemsSource="{Binding Source={StaticResource MyCVS}}" ItemTemplate="{StaticResource ItmesTemplate}" ItemContainerStyle="{StaticResource ItemChildStyle}" SelectedItem="{Binding SelectedItem}" >
<ListBox.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupStyle}" />
<GroupStyle ContainerStyle="{StaticResource Group2Style}" />
</ListBox.GroupStyle>
</ListBox>
public class ItemViewModel : ViewModelBase
{
public string GroupName { get; set; }
public string SubGroupName{ get; set; }
public string ItemName { get; set; }
public bool IsExpanded {get; set;}
}
Опубликовать больше кода о ViewModel и более XAML –
Дайте мне знать, если есть другой код, который вы хотели бы видеть. – user1336827