Skip to content

Commit dddeb51

Browse files
committed
add command sample
1 parent 8a0a8d6 commit dddeb51

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

hub/powertoys/command-palette/microsoft-commandpalette-extensions/icommand.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: ICommand Interface
33
description: Action a user can take within the Command Palette.
4-
ms.date: 2/6/2025
4+
ms.date: 2/7/2025
55
ms.topic: reference
66
no-loc: [PowerToys, Windows, Insider]
77
---
@@ -21,3 +21,7 @@ Action a user can take within the Command Palette.
2121
| Name | String | Gets the name of the command. |
2222
| Id | String | Gets the ID of the command. |
2323
| Icon | [IIconInfo](iiconinfo.md) | Gets the icon of the command. |
24+
25+
## Samples
26+
27+
[Add a command](../samples.md#add-a-command)

hub/powertoys/command-palette/microsoft-commandpalette-extensions/iinvokablecommand_invoke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ no-loc: [PowerToys, Windows, Insider]
1212

1313
Namespace: [Microsoft.CommandPalette.Extensions](microsoft-commandpalette-extensions.md)
1414

15+
The method called when a user selects a command.
16+
1517
## Parameters
1618

1719
`sender` Object
1820

1921
## Returns
2022

2123
[ICommandResult](icommandresult.md)
24+
25+
## Samples
26+
27+
[Add a command](../samples.md#add-a-command)
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
---
22
title: Command Palette Extension Samples
33
description: The Command Palette provides a full extension model, allowing developers to create their own experiences for the palette. Find available samples to get started with creating an extension.
4-
ms.date: 2/3/2025
4+
ms.date: 2/7/2025
55
ms.topic: concept-article
66
no-loc: [PowerToys, Windows, Insider]
77
# Customer intent: As a Windows developer, I want to see samples of Command Palette extensions so I can learn how to write one.
88
---
99

10-
# Extension samples
10+
# Extension samples
11+
12+
## Add a command
13+
14+
Create a class that implements [ICommand](./microsoft-commandpalette-extensions/icommand.md) and implement the [Invoke](./microsoft-commandpalette-extensions/iinvokablecommand_invoke.md) method. This method will be called whtn the user selects the command in the Command Palette.
15+
16+
```C#
17+
class MyPage : Microsoft.CommandPalette.Extensions.Toolkit.InvokableCommand {
18+
public class MyPage()
19+
{
20+
Name = "My Page Name";
21+
Icon = "PATH_TO_ICO";
22+
}
23+
24+
// Open MY_WEBSITE_URL in the user's default web browser
25+
public ICommandResult Invoke() {
26+
Process.Start(new ProcessStartInfo("MY_WEBSITE_URL") { UseShellExecute = true });
27+
return CommandResult.Hide();
28+
}
29+
}
30+
```

0 commit comments

Comments
 (0)