mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Implemented IDetailsCommands in details. This will close #38339. This works very similar to Tags in that it is a list of commands. This was done to allow for styling without the 12 spacing of the ItemsRepeater and looks like you'd find in the OS-inbox like:   Also added to our sample extension: 
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using Microsoft.CmdPal.UI.ViewModels.Models;
|
|
using Microsoft.CommandPalette.Extensions;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|
|
|
public partial class DetailsCommandsViewModel(
|
|
IDetailsElement _detailsElement,
|
|
WeakReference<IPageContext> context) : DetailsElementViewModel(_detailsElement, context)
|
|
{
|
|
public List<CommandViewModel> Commands { get; private set; } = [];
|
|
|
|
public bool HasCommands => Commands.Count > 0;
|
|
|
|
private readonly ExtensionObject<IDetailsCommands> _dataModel =
|
|
new(_detailsElement.Data as IDetailsCommands);
|
|
|
|
public override void InitializeProperties()
|
|
{
|
|
base.InitializeProperties();
|
|
var model = _dataModel.Unsafe;
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Commands = model
|
|
.Commands?
|
|
.Select(c =>
|
|
{
|
|
var vm = new CommandViewModel(c, PageContext);
|
|
vm.InitializeProperties();
|
|
return vm;
|
|
})
|
|
.ToList() ?? [];
|
|
UpdateProperty(nameof(HasCommands));
|
|
UpdateProperty(nameof(Commands));
|
|
}
|
|
}
|