我有一个ListBox,填充了CollectionViewSource,以便将项目分组。
<ListBox
x:Name="Positions"
Margin="10,0,0,0"
BorderThickness="0"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding Source={StaticResource cvsItems}}"
SelectedItem="{Binding SelectedItem}"
SelectionMode="Extended">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Horizontal">
<Separator
Margin="-8,-19,10,11"
SnapsToDevicePixels="True"
Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"
Visibility="{Binding IsPartOfAverageGroup, Converter={StaticResource boolToVisibilityConverter}}" Grid.ZIndex="1"/>
<Separator
Width="40"
Margin="-10,0,8,0"
SnapsToDevicePixels="True"
Visibility="{Binding IsPartOfAverageGroup, Converter={StaticResource boolToVisibilityConverter}}" />
<TextBlock Text="{Binding Name}" />
<Image
Height="12"
Margin="5,0,0,0"
Source="/Images/2017/Editable.png">
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<DataTrigger Binding="{Binding IsReadOnly}" Value="True">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style BasedOn="{StaticResource ListBoxItemStyle}" TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Ellipse
Width="8"
Height="8"
Margin="1,0,0,0"
Grid.ZIndex="10000"
Fill="#0589D1" />
<Button
Margin="15,0,0,0"
HorizontalContentAlignment="Left"
cal:Message.Attach="SelectAverageGroup($dataContext)"
Content="{Binding Name}" />
<StackPanel.Style>
<Style TargetType="StackPanel">
<Style.Triggers>
<DataTrigger Binding="{Binding Name}" Value="">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
这是我的CollectionViewSource:
<UserControl.Resources>
<CollectionViewSource x:Key="cvsItems" Source="{Binding Items}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="AverageGroup.Name" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</UserControl.Resources>
您可以在DataTemplate中看到ListBox,我想绘制连接Group Header和分组项的行。这是一张图片来澄清:
我希望蓝色圆圈位于灰线前面,而不是相反。我试图将垂直灰色分隔符的ZIndex和蓝色圆圈的ZIndex设置为1000,以便后者位于前面。我在这做错了什么?感谢您对此的任何帮助。