ToolkitSampleButtonAction Attribute
Describe the bug
Many samples need the option to perform an action or demonstrate a triggered event (like a notification for instance).
For instance, the current notification behavior needs to have button as part of its sample code:
https://github.com/CommunityToolkit/Labs-Windows/blob/ce74acf608383502e42cd903b660d45f281281bb/components/StackedNotificationsBehavior/samples/StackedNotificationsBehaviorCustomSample.xaml#L14-L17
We should instead be able to show this as part of the sidebar of options available for the sample to present these types of actions in a consistent pattern and minimize the XAML to be that which is required for the feature in typical usage.
Steps to reproduce
N/A
Expected behavior
Proposal:
[ToolkitSampleButtonAction(string commandName, string buttonLabel, string methodName, bool isVisible = true)]
[ToolkitSampleButtonAction("SendMessage", "Send Notification", nameof(SendNotificationMessage), Title = "Optional Header"]
public sealed partial class MySimpleSample : Page
{
public MySimpleSample()
{
this.InitializeComponent();
}
public void SendNotificationMessage()
{
// Code to run when button is clicked
}
This would create a button on the side panel which when clicked would execute the method of the given sample class, in the above TestMethod. It would also create a named SendMessageCommand which could be leveraged in the sample XAML code for other purposes as well if some embedded UI element also needed a command version of it to trigger in an alternate way or if isVisible is set to false to use just as a command but not show in the sidebar.
Don't think there's a better way to connect the method to the attribute... @Sergio0694? I suppose we could put the attribute on the method in the class instead? Would separate it from our other options, but make it clearer and remove the need for nameof. Would also make it easier if we wanted to remove that method from the displayed sample code:
public sealed partial class MySimpleSample : Page
{
public MySimpleSample()
{
this.InitializeComponent();
}
[ToolkitSampleButtonAction("SendMessage", "Send Notification", Title = "Optional Header"]
public void SendNotificationMessage()
{
// Code to run when button is clicked
}
Screenshots
No response
Code Platform
- [ ] UWP
- [ ] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK
Windows Build Number
- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)
Other Windows Build number
No response
App minimum and target SDK version
- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Other (specify)
Other SDK version
No response
Visual Studio Version
No response
Visual Studio Build Number
No response
Device form factor
No response
Additional context
No response
Help us help you
Yes, but only if others can assist.