|
| 1 | +--- |
| 2 | +title: Filters Class - Command Palette Extensions Toolkit |
| 3 | +description: The Filters class is used to get and manage the filters applied to the command palette. |
| 4 | +ms.date: 09/04/2025 |
| 5 | +ms.topic: reference |
| 6 | +no-loc: [PowerToys, Windows, Insider] |
| 7 | +--- |
| 8 | + |
| 9 | +# Filters Class |
| 10 | + |
| 11 | +## Definition |
| 12 | + |
| 13 | +Namespace: [Microsoft.CommandPalette.Extensions.Toolkit](microsoft-commandpalette-extensions-toolkit.md) |
| 14 | + |
| 15 | +Implements **BaseObservable**, [IFilters](../microsoft-commandpalette-extensions/ifilters.md) |
| 16 | + |
| 17 | +The **Filters** class is used to get and manage the filters applied to the command palette. |
| 18 | + |
| 19 | +## Properties |
| 20 | + |
| 21 | +| Property | Type | Description | |
| 22 | +| :--- | :--- | :--- | |
| 23 | +| CurrentFilterId | **String** | The ID of the currently applied filter. | |
| 24 | + |
| 25 | +## Methods |
| 26 | + |
| 27 | +| Method | Description | Returns | |
| 28 | +| :--- | :--- | :--- | |
| 29 | +| GetFilters | Gets the list of filters. This method should be overridden in derived classes to provide the actual filters. | **IFilterItem\[\]** | |
| 30 | + |
| 31 | +## Example |
| 32 | + |
| 33 | +The following example demonstrates how to create a custom filter class by inheriting from the **Filters** class. |
| 34 | + |
| 35 | +```csharp |
| 36 | +public partial class ServiceFilters : Filters |
| 37 | +{ |
| 38 | + // Constructor where CurrentFilterId is set to the default filter |
| 39 | + public ServiceFilters() |
| 40 | + { |
| 41 | + // This would be a default selection. Not providing this will cause the filter |
| 42 | + // control to display the "Filter" placeholder text. |
| 43 | + CurrentFilterId = "all"; |
| 44 | + } |
| 45 | + |
| 46 | + // Override GetFilters method to provide custom filters |
| 47 | + public override IFilterItem[] GetFilters() |
| 48 | + { |
| 49 | + return [ |
| 50 | + new Filter() { Id = "all", Name = "All Services" }, |
| 51 | + new Separator(), |
| 52 | + new Filter() { Id = "running", Name = "Running", Icon = Icons.GreenCircleIcon }, |
| 53 | + new Filter() { Id = "stopped", Name = "Stopped", Icon = Icons.RedCircleIcon }, |
| 54 | + new Filter() { Id = "paused", Name = "Paused", Icon = Icons.PauseIcon }, |
| 55 | + ]; |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
0 commit comments