WinUI-Gallery icon indicating copy to clipboard operation
WinUI-Gallery copied to clipboard

Added a Scratch Pad page where sample xaml can be loaded

Open codendone opened this issue 1 year ago • 0 comments

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)
  • [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.

Bonus fix

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

codendone avatar May 21 '24 17:05 codendone