Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Scratch Pad page where sample xaml can be loaded #1548

Merged
merged 13 commits into from
May 22, 2024

Conversation

codendone
Copy link
Contributor

Description

Added a “Scratch Pad” page to the gallery where the user can type in some XAML markup and click the Load button to immediately see the results. This provides a convenient place for experimentation. It can also be used to provide a simple repro for issues which only require loading the right XAML markup.

This change currently adds the “Scratch Pad” page to the “System” group in the navigation pane. This seems like the best fit currently, without a “Tools” section or something else.

Details about the Scratch Pad

  • There is syntax coloring for the XAML in the RichEditBox on the page. The syntax coloring only updates on Load.
  • The user can press F5 when focus is in the RichEditBox to trigger a Load.
  • The XAML markup is stored in application data on Load. This stored XAML is loaded the next time the user returns to Scratch Pad, even on a fresh launch of WinUI 3 Gallery.
  • There is some basic auto-indenting, auto close-tag insertion, and auto property-quotes insertion handling.

Known issues/limitations

  • Syntax coloring only updates on Load.
  • The undo stack of the RichEditBox contains an extra undo every time the syntax coloring is applied. (This is the main reason it isn’t applied every time the text changes.)
  • {x:Bind} is not supported and will cause a load error. A possible future improvement would be to strip out any such properties to load as much as possible.
  • Events (like Button.Click event) appear to not cause errors, but don’t get connected to anything.
  • If either the content or the xaml markup textbox get too tall, they expand to take as much space as needed. It would be nicer for individual ScrollViewers to scroll when needed, which would require overriding the standard ScrollViewr on ItemsPage.xml.

How Has This Been Tested?

Tested loading a variety of markup. Tested its ability to save and load small and large markup to app data. Tested the "Toggle Theme" button to ensure it behaves well. Tested with Accessibility Insights to ensure there weren't any issues.

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Some possible future improvements

  • Maybe support choosing from multiple default samples to load.
  • Maybe support saving and loading multiple user-named samples.
  • Maybe add a way for every control sample in the app to be able to navigate to Scratch Pad with the content of that sample.

Bonus fix

Removed an unused variable in IconsPage.xaml.cs to remove a compiler warning.

@codendone
Copy link
Contributor Author

/azp run

@codendone
Copy link
Contributor Author

/azp run

@karkarl
Copy link
Collaborator

karkarl commented May 22, 2024

Thanks for this PR, I'm very excited for this! We can create a separate NavView Item and put this page under "Tools". This can be in the next PR.

@codendone codendone merged commit cb7c59a into main May 22, 2024
2 checks passed
@karkarl karkarl deleted the user/codendone/scratchPad branch June 17, 2024 23:12
karkarl pushed a commit that referenced this pull request Jul 15, 2024
## Description
Added a “Scratch Pad” page to the gallery where the user can type in
some XAML markup and click the Load button to immediately see the
results. This provides a convenient place for experimentation. It can
also be used to provide a simple repro for issues which only require
loading the right XAML markup.

This change currently adds the “Scratch Pad” page to the “System” group
in the navigation pane. This seems like the best fit currently, without
a “Tools” section or something else.

## Details about the Scratch Pad
* There is syntax coloring for the XAML in the RichEditBox on the page.
The syntax coloring only updates on Load.
* The user can press F5 when focus is in the RichEditBox to trigger a
Load.
* The XAML markup is stored in application data on Load. This stored
XAML is loaded the next time the user returns to Scratch Pad, even on a
fresh launch of WinUI 3 Gallery.
* There is some basic auto-indenting, auto close-tag insertion, and auto
property-quotes insertion handling.

## Known issues/limitations
* Syntax coloring only updates on Load.
* The undo stack of the RichEditBox contains an extra undo every time
the syntax coloring is applied. (This is the main reason it isn’t
applied every time the text changes.)
* `{x:Bind}` is not supported and will cause a load error. A possible
future improvement would be to strip out any such properties to load as
much as possible.
* Events (like Button.Click event) appear to not cause errors, but don’t
get connected to anything.
* If either the content or the xaml markup textbox get too tall, they
expand to take as much space as needed. It would be nicer for individual
ScrollViewers to scroll when needed, which would require overriding the
standard ScrollViewr on ItemsPage.xml.

## How Has This Been Tested?
Tested loading a variety of markup. Tested its ability to save and load
small and large markup to app data. Tested the "Toggle Theme" button to
ensure it behaves well. Tested with Accessibility Insights to ensure
there weren't any issues.

## Screenshots (if appropriate):

![image](https://github.com/microsoft/WinUI-Gallery/assets/45052236/35e28cba-9476-4272-87c9-acd056c6377d)

## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Some possible future improvements
* Maybe support choosing from multiple default samples to load.
* Maybe support saving and loading multiple user-named samples.
* Maybe add a way for every control sample in the app to be able to
navigate to Scratch Pad with the content of that sample.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants