Fix the AOT issue with custom binding of IsSelected property through CVS in Mail List.

This commit is contained in:
Burak Kaan Köse
2025-12-28 07:28:20 +01:00
parent 0f6aa66b21
commit f79305f0a6
5 changed files with 70 additions and 5 deletions
@@ -1,12 +1,17 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using CommunityToolkit.WinUI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Wino.Controls;
using Wino.Helpers;
using Wino.Mail.ViewModels.Data;
using WinRT;
namespace Wino.Mail.WinUI.Controls.ListView;
[GeneratedBindableCustomProperty]
public partial class WinoThreadMailItemViewModelListViewItem : ListViewItem
{
[GeneratedDependencyProperty]
@@ -15,6 +20,8 @@ public partial class WinoThreadMailItemViewModelListViewItem : ListViewItem
[GeneratedDependencyProperty]
public partial ThreadMailItemViewModel? Item { get; set; }
[GeneratedDependencyProperty]
public partial bool IsCustomSelected { get; set; }
public WinoThreadMailItemViewModelListViewItem()
{
@@ -31,4 +38,25 @@ public partial class WinoThreadMailItemViewModelListViewItem : ListViewItem
}
public WinoExpander? GetExpander() => WinoVisualTreeHelper.FindDescendants<WinoExpander>(this).FirstOrDefault();
partial void OnItemPropertyChanged(DependencyPropertyChangedEventArgs e)
{
Debug.WriteLine("WinoMailItemViewModelListViewItem item changed");
if (e.OldValue is ThreadMailItemViewModel oldMailItemViewModel) UnregisterPropertyChanged(oldMailItemViewModel);
if (e.NewValue is ThreadMailItemViewModel newMailItemViewModel) RegisterPropertyChanged(newMailItemViewModel);
}
private void RegisterPropertyChanged(ThreadMailItemViewModel model) => model.PropertyChanged += ModelPropertyChanged;
private void UnregisterPropertyChanged(ThreadMailItemViewModel model) => model.PropertyChanged -= ModelPropertyChanged;
private void ModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (sender is not ThreadMailItemViewModel mailItemViewModel) return;
if (e.PropertyName == nameof(ThreadMailItemViewModel.IsSelected))
{
IsCustomSelected = mailItemViewModel.IsSelected;
}
}
}