CollectionView causing DisconnectedItem on CheckBox

I've a CollectionViewSource implemented in this way:

    <CollectionViewSource Source="{Binding CustomMatches}" x:Key="GroupedItems">
            <PropertyGroupDescription PropertyName="League" />

The Collection CustomMatches have the following structure:

public ObservableCollection<CustomMatch> CustomMatches = new ObservableCollection<CustomMatch>();

public class CustomMatch
      public League League { get; set; }
      public string Name { get; set; }

public class League 
    public string Name { get; set; }

then in my ListView there is this group implementation:

         <GridViewColumn Header="{DynamicResource date}" Width="150" DisplayMemberBinding="{Binding Path = Name}"/>

                <Style TargetType="{x:Type GroupItem}" >
                    <Setter Property="Template">
                                <Expander IsExpanded="True" Background="#4F4F4F">
                                        <DockPanel Height="16.5">
                                            <TextBlock Text="{Binding Name.Name}" FontWeight="Bold" Foreground="White" FontSize="11.5" VerticalAlignment="Bottom" />

                                            <CheckBox IsChecked="{Binding Name.IsFavourite}" 
                                                      Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"
                                                      Style="{StaticResource CheckBoxStar}"/>

                                    <ItemsPresenter />

all is grouped well, but there is a problem, when I click on the checkbox available in the header I'll get DisconnectedItem on the DataContext property of the CheckBox:

private void CheckBox_Checked(object sender, RoutedEventArgs e)
        var item = ((sender as CheckBox).DataContext as CollectionViewGroup).Name as League;

why happen this?

1 answer

  • answered 2018-01-14 17:12 Milan

    your code still doesnt compile, and i cant edit enough code to get your problem. you really need to put more effort into making your question clear...

    as blins above said, you should try to disable virtualization for your listview and see if that helps.

    by default, ListView, which is a ListBox, has a VirtualizingStackPanel as its items panel, so with the following code snippet, you put a simple stackpanel instead.