Repository: microsoft/PowerToys
File: src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/ListItemViewModel.cs (C#)

Code before:
    {
        var newTags = newTagsFromModel?.Select(t =>
        {
            var vm = new TagViewModel(t, PageContext);
            vm.InitializeProperties();
            return vm;
        })
            .ToList() ?? [];

        DoOnUiThread(
            () =>
            {
                // Tags being an ObservableCollection instead of a List lead to
                // many COM exception issues.
                Tags = [.. newTags];

                UpdateProperty(nameof(Tags));
                UpdateProperty(nameof(HasTags));
            });
    }

    protected override void UnsafeCleanup()
    {
        base.UnsafeCleanup();

        // Tags don't have event handlers or anything to cleanup
        Tags?.ForEach(t => t.SafeCleanup());
        Details?.SafeCleanup();

        var model = Model.Unsafe;
        if (model is not null)
        {
            // We don't need to revoke the PropChanged event handler here,
            // because we are just overriding CommandItem's FetchProperty and
            // piggy-backing off their PropChanged
        }
    }

    protected void UpdateAccessibleName()
    {
        AccessibleName = Title + ", " + Subtitle;
        UpdateProperty(nameof(AccessibleName));
    }
}


Review comment (bug):
It might be a good idea to add a separator before the new item if the `MoreCommands` is not empty. With the addition of separators, developers might start using it to group the commands, and then "Show Details" might end up visually in the wrong group, making it look unpolished.

Code after:
    // TODO: Do we want to save off the score here so we can sort by it in our ListViewModel?
    public override string ToString() => $"{Name} ListItemViewModel";

    public override bool Equals(object? obj) => obj is ListItemViewModel vm && vm.Model.Equals(this.Model);

    public override int GetHashCode() => Model.GetHashCode();

    private void AddShowDetailsCommands()
    {
        // If the parent page has ShowDetails = false and we have details,
        // then we should add a show details action in the context menu.
        if (HasDetails &&
            PageContext.TryGetTarget(out var pageContext) &&
            pageContext is ListViewModel listViewModel &&
            !listViewModel.ShowDetails)
        {
            // Check if "Show Details" action already exists to prevent duplicates
            if (!MoreCommands.Any(cmd => cmd is CommandContextItemViewModel contextItemViewModel &&
                                        contextItemViewModel.Command.Id == ShowDetailsCommand.ShowDetailsCommandId))
            {
                // Create the view model for the show details command
                var showDetailsCommand = new ShowDetailsCommand(Details);
                var showDetailsContextItem = new CommandContextItem(showDetailsCommand);
                var showDetailsContextItemViewModel = new CommandContextItemViewModel(showDetailsContextItem, PageContext);
                showDetailsContextItemViewModel.SlowInitializeProperties();
                MoreCommands.Add(showDetailsContextItemViewModel);
            }

            UpdateProperty(nameof(MoreCommands));
            UpdateProperty(nameof(AllCommands));
        }
    }

    // This method is called when the details change to make sure we
    // have the latest details in the show details command.
    private void UpdateShowDetailsCommand()
    {
        // If the parent page has ShowDetails = false and we have details,
        // then we should add a show details action in the context menu.
        if (HasDetails &&
            PageContext.TryGetTarget(out var pageContext) &&
            pageContext is ListViewModel listViewModel &&
            !listViewModel.ShowDetails)
        {
            var existingCommand = MoreCommands.FirstOrDefault(cmd =>
                                        cmd is CommandContextItemViewModel contextItemViewModel &&
                                        contextItemViewModel.Command.Id == ShowDetailsCommand.ShowDetailsCommandId);

            // If the command already exists, remove it to update with the new details
            if (existingCommand is not null)
            {