Чтобы воспроизвести эту проблему, добавьте пользовательский элемент управления, вставьте ниже xaml, а затем добавьте экземпляр в окно. Наконец, установите для текстового контекста окна экземпляр ADummyDataContext (также ниже)
Когда вы запускаете приложение в первый раз, вы должны получить сетку с тремя категориями, в каждой из которых содержится один кот. Если щелкнуть одну из двух нижних категорий и щелкнуть имя кошки, появится синяя строка, показывающая только имя кошки.
Однако, если вы щелкнете по первой строке и щелкните по строке кошки, синяя строка не появится.
ПРИМЕЧАНИЕ : это происходит только при первом запуске приложения. Как только вы нажмете на любую другую кошку, кошка в первой категории будет работать как положено.
<UserControl x:Class="WpfUserControls.SimpleGridControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="#FFE46400">
<Grid Margin="2,2,2,2">
<Grid.RowDefinitions>
<RowDefinition Height="26" MaxHeight="26" MinHeight="26" />
<RowDefinition />
<RowDefinition Height="26" MaxHeight="26" MinHeight="26" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ToolBar Grid.Row="0">
<Button Content="Button" Name="button1" VerticalAlignment="Center" Width="75" />
<Button Content="Button" Name="button2" VerticalAlignment="Center" Width="75" />
</ToolBar>
<DataGrid CanUserAddRows="False" ItemsSource="{Binding Path=KittensView}" AutoGenerateColumns="True" Grid.Row="1" HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" Margin="0,0,5,0"/>
<TextBlock Text="{Binding Path=ItemCount}"/>
<TextBlock Text=" Items"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Background="LightBlue" Orientation="Horizontal" >
<!-- <Image Height="32" Width="32" Source="/WpfUserControls;component/cat.png"></Image> -->
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Height ="20" Text="{Binding Path=Name}"/>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
<StatusBar Grid.Row="2"></StatusBar>
</Grid>
</UserControl>
А вот класс контекста данных и класс Kitten.
public class ADummyDataContext
{
public List<Kitten> Kittens { get; set; }
public ADummyDataContext()
{
Kittens = new List<Kitten>
{
new Kitten {Color = "Orange", Name = "Alfie", Weight=6, Sex="Male"},
new Kitten {Color = "Black and White", Name = "Smudge", Weight = 4, Sex="Female"},
new Kitten {Color = "Grey", Name = "Charlotte", Weight = 5, Sex="Female"}
};
KittensView = new ListCollectionView(Kittens);
KittensView.GroupDescriptions.Add(new PropertyGroupDescription("Weight"));
}
public ListCollectionView KittensView { get; set; }
}
public class Kitten
{
public string Name { get; set; }
public string Color { get; set; }
public int Weight { get; set; }
public string Sex { get; set; }
}
Мне было бы особенно интересно узнать, как вы понимаете, в чем здесь проблема.
Спасибо