问题
I have a ListView IsGroupedSource is set to true in it's CollectionViewSource. I'm trying to toggle a groups visibility when it's group header is clicked.
<CollectionViewSource
x:Name="FiltersViewSource"
Source="{Binding Filters}"
IsSourceGrouped="true"
ItemsPath="AttributeValues"
/>
<ListView
x:Name="filtersListView"
AutomationProperties.AutomationId="ItemListView"
AutomationProperties.Name="Grouped Items"
Grid.Row="1"
Margin="0,-10,0,0"
Padding="30"
ItemsSource="{Binding Source={StaticResource FiltersViewSource}}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="7,7,0,0">
<Button AutomationProperties.Name="Group Title"
Click="Header_Click"
Style="{StaticResource TextPrimaryButtonStyle}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Foreground="White" FontSize="35" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
<TextBlock Text="{StaticResource ChevronGlyph}" Foreground="White" HorizontalAlignment="Right" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
</StackPanel>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,0,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemTemplate>
<DataTemplate >
<StackPanel Visibility="{Binding Visibility}" Orientation="Horizontal">
<CheckBox Margin="0,0,20,0"/>
<TextBlock Text="{Binding Name}" Style="{StaticResource ItemTextStyle}" Foreground="White" FontSize="20" MaxHeight="40"/>
<TextBlock Text="(40)" Style="{StaticResource ItemTextStyle}" Foreground="White" FontSize="25" MaxHeight="40"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Basically I'm trying to create an accordion style list. I tried adding.
<VariableSizedWrapGrid Visibility="{Binding Visibility}" Orientation="Vertical" Margin="0,0,0,0"/>
Visbility is a property of type Visibility in the underlying group object.
But it doesn't work.
Is there anyway to accomplish this?
回答1:
You could try binding the Header Button's Command property to a view model command that changes a group view model Visibility property that you would bind to your VariableSizedWrapGrid.
来源:https://stackoverflow.com/questions/15929515/windows-store-xaml-and-c-sharp-how-to-create-accordian-style-list