Modern Adorners #278
Replies: 2 comments 8 replies
-
Tinkering with ideas for XAML based attaching/initializing of adorners. Obviously, it'd be one of these types of things, but just iterating on different ideas together here: <Button labs:Adorner.Attach="local:MyAdornerType"> <!-- auto-instantiate by type, reflection is meh -->
<SymbolIcon Symbol="Mail" HorizontalAlignment="Center"/>
<labs:Adorner.Xaml> <!-- Simple helper to add xaml directly as an adornment, but then how do we control position, etc...? -->
<muxc:InfoBadge Value="5"/>
</labs:Adorner.Xaml>
<labs:Adorner.Attach> <!-- More generalized point -->
<local:MyAdornerType/> <!-- Take initialized by xaml version, would need property to get element from attach helper? -->
<labs:XamlAdorner Offset="??"> <!-- Then we could have our own XAML based adorner to helper here instead which could have more options... -->
<muxc:InfoBadge Value="5"/>
</labs:XamlAdorner>
</labs:Adorner.Attach>
</Button> |
Beta Was this translation helpful? Give feedback.
-
Started a branch here: https://github.com/michael-hawker/Labs-Windows/tree/llama/adorners/labs/Adorners Had a lot of trouble trying to auto-inject a AdornerLayer and re-parent the content of the app scroll viewer. Kept getting the child of another element exception even after waiting for content to be set to null or content unloaded event to fire... 🙁 So easy to add a badge to a button though now with this initial exploration: <Grid>
<Button>
<SymbolIcon HorizontalAlignment="Center"
Symbol="Mail" />
<labs:AdornerLayer.Xaml>
<muxc:InfoBadge Margin="-4"
HorizontalAlignment="Right"
VerticalAlignment="Top"
IsHitTestVisible="False"
Value="5" />
</labs:AdornerLayer.Xaml>
</Button>
<!-- Dev should have this as part of their main host window/page content above the frame -->
<labs:AdornerLayer />
</Grid> Even stumbled into the Still many things to investigate and test around scrolling, resizing, and visibility of the adorned element. But it's a start! |
Beta Was this translation helpful? Give feedback.
-
Adorners
Problem Statement
Adorners were a big feature in WPF for creative experiences in visual and textual editors to highlight parts of the UI for contextual interaction by a user (among other things).
This experiment is going to investigate how they work in WPF and how we might polyfill that functionality into UWP/WinUI using new components from the Windows Community Toolkit Labs.
Ideally, we have a similar experience and API surface with possible extensions for improvements to tie Adorners more to the XAML layer. At least showing some common patterns/experiences from Adorners done in WPF replicated in UWP/WinUI.
Most-likely out-of-scope is investigating/addressing the obvious gap in OnRender/DrawingContext methods from UIElement compared to WPF.
Inspiration
Much called out gap from WPF in implementing certain types of experiences.
Implementation of #212 and #213 type controls, provide an easy to use panel that may be of use for this type of overlay system.
There's also the ScrollViewerExtensions for animating/syncing content in a scrollviewer which could be handy?
XAML Behaviors and how behaviors work I think will play a role in how a modern Adorner system could work.
Proposed Solution
Overall ideas around architecture
There'll be some sort of
AdornerLayer
type component which represents theCanvas
type space that adorners live on above all other components of an app. I think when the firstAdorner
is attempted to be used, an AdornerLayer is searched for and injected if none found? Otherwise, we have to leave it up to the developer to specify one within their app (which I think allowing and targeting specific layers would be good to have anyway).Adorner
can be subclassed by an implementor for specific 'behaviors' that can be shared. However, it'd be nice if there was a way to just inject XAML to be shown/placed on the adorner layer without having to write specific implementations using anAdorner
class. In this case it'd be nice if there was an easy way to toggle theAdorner
on/off, maybe that's just visibility?Adorner
s should know where their attached component is in relation to the display surface (i.e. able to use relative coordinates for layout).API Surface
Been using a
labs:AdornerLayer.Xaml
attached property helper at the moment, but expect that to be temporary and turn into it's own Adorner helper that is shipped with this feature.Expect the actual API surface to be something like:
We want an
AdornerDecorator
helper to help establish a way for a developer to inject their own AdornerLayers (especially at the top-level due to issues with RootScrollViewer (TODO Link to WinUI issue to be filed)):From https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/Themes/XAML/Window.xaml
Open Questions
API Reference Docs
References
Platform Issues
Beta Was this translation helpful? Give feedback.
All reactions