mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
cmdpal: A sample for tracking load/unload for pages (#39265)
Committing this sample for posterity's sake. This is the product of an experiment: "can an extension know when it's page was opened / closed?" And without changing the actual SDK, this **is** possible. It relies on the fact that CmdPal (the host) needs to register for the `ItemsChanged` event on list pages, and it does that when the page is loaded, and it unregisters itself when the page is closed. This does require manually implementing `IListPage` - you can't just `override` the `event` in the base class ([that's illegal](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1070)), and using `new` to shadow it doesn't work either (probably for cswinrt reasons). This is the best I came up with.
This commit is contained in:
@@ -32,6 +32,11 @@ public partial class SamplesListPage : ListPage
|
||||
Title = "Dynamic List Page Command",
|
||||
Subtitle = "Changes the list of items in response to the typed query",
|
||||
},
|
||||
new ListItem(new OnLoadPage())
|
||||
{
|
||||
Title = "Demo of OnLoad/OnUnload",
|
||||
Subtitle = "Changes the list of items every time the page is opened / closed",
|
||||
},
|
||||
|
||||
// Content pages
|
||||
new ListItem(new SampleContentPage())
|
||||
|
||||
Reference in New Issue
Block a user