WPF Framework not unsubscribing from Button.Command’s CanExecuteChanged event

In my WPF application, I have a DataGrid (virtualization disabled for both rows and columns). The ItemsSource of the DataGrid is an ObservableCollection< ItemViewModel >. On my first column’s CellTemplate, I have some elements including this Button :

<Button Grid.Column="1"
        Margin="0 0 4 0"
        Visibility="{Binding CanView, Converter={StaticResource BoolToVisibilityConverter}}"
        Style="{StaticResource ToolStripRowButtonStyle}"
        Command="{Binding ViewCommand}"
        CommandParameter="{Binding}">
    <Image Source="pack://application:,,,/SomeApp;component/Resources/View.png"/>
</Button>

ViewCommand is a custom command imlementing ICommand. I implemented the CanExecuteChanged event such that a counter is incremented for each registration to the event and decremented for each unregistration from the event.

When ItemViewModels are added to the collection, I see that rows are created and I see my registration counter increment by one each time which is what I expect.

But when I remove some ItemViewModels from the collection, even though I see that the rows disappear from the UI, my registration counter never decrements. And indeed, if I trigger the CanExecuteChanged, I see that my Command.CanExecute(param) is called with the CommandParameter of older items that were previously removed. This confirms that the Framework did NOT unregister the old buttons from the commands’ CanExecuteChanged events.

Puzzling fact: I will sometimes see a decrement or two slide in, but never in a systematic way and never in a way that allowed me to understand what is going on.

I am genuinely expecting that as soon as an item is removed from the collection, its row would be destroyed and all its reference to its ItemViewModel would be released. I can’t understand why an old row is somewhat “staying alive”.

Extra info:
I am also providing this extra info that I am also observing and that I think should not happen, just in case it is somewhat related and helps someone figure out the issues.

In my second DataGrid column’s CellTemplate, I have this trigger:

<DataTrigger Binding="{Binding ElementName=m_dataGrid, Path=DataContext.CanEdit}" Value="False">
    <Setter Property="IsEnabled" Value="False"/>
</DataTrigger>

Also when I remove an ItemViewModel from the collection, when the corresponding row is removed, I get an error about the binding not being resolved. I find it strange because since the row should be removed, I don’t understand why the Framework is still trying to resolve the binding. Once again, it is as if the row is somehow still alive.

The error I get is:

System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘ElementName=m_dataGrid’. BindingExpression:Path=DataContext.CanEdit; DataItem=null; target element is ‘DataGridCell’ (Name=”); target property is ‘NoTarget’ (type ‘Object’)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật