Я пытаюсь создать пользовательский элемент управления для группировки сетки данных. Первоначальное усилие было создать пользовательский элемент управления и поместить рабочую структуру Expander в пользовательский элемент управления. Расширители групп отлично отображаются с именем и итогами, однако содержимое расширителя не отображается. Многочисленные методы отображения данных оказались безуспешными. Какой аспект использования пользовательского элемента управления упускается из виду?
![enter image description here](https://i.stack.imgur.com/op8Nc.png)
Исходная группа XAML перед созданием пользовательского элемента управления
<DataGrid.GroupStyle >
<GroupStyle >
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}" >
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander Background="LightBlue">
<Expander.Header>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Name}" Margin="5"/>
<TextBlock Text="{Binding ItemCount, StringFormat='[{0} items]'}" VerticalAlignment="Center"/>
</StackPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
Пользовательский элемент управления
<UserControl x:Class="Company.Utilities.Controls.ucExpanderGroupItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Company.Utilities.UI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Expander Background="LightBlue">
<Expander.Header>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Name}" Margin="5"/>
<TextBlock Text="{Binding ItemCount, StringFormat='[{0} items]'}" VerticalAlignment="Center"/>
</StackPanel>
</Expander.Header>
<!--Here are the multiple ways that have been attempted to display the data-->
<!--<ContentPresenter Content="{Binding Value}" />-->
<!--<ContentControl Content="{Binding Value}" />-->
<!--<ItemsPresenter />-->
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</UserControl>
.........
public partial class ucExpanderGroupItem : UserControl
{
public ucExpanderGroupItem()
{
InitializeComponent();
}
}
Основной XAML, который ссылается на элемент управления пользователя
<DataGrid.GroupStyle >
<GroupStyle >
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}" >
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<utilctl:ucExpanderGroupItem/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>