CommunityToolkit / CommunityToolkit/Tooling-Windows-Submodule
ToolkitSampleButtonAction Attribute
- Dominant language
- C#
- Stars
- 55
- Forks
- 19
- Avg merge
- 40m
- Merged PRs (30d)
- 1
Description
### 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
```text
N/A
```
### Expected behavior
Proposal:
```cs
[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:
```cs
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.
Contributor guide
Assessment
This issue has not been assessed yet.