question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Support ThemeShadow entirely within XAML

See original GitHub issue

Proposal: Support ThemeShadow entirely within XAML

Summary

I know I’ll get some flack for calling this a bug but I consider it one 😃 ThemeResource cannot be used without registering the control with the shadow in code-behind. This is a design bug in the way ThemeShadows are implemented. It breaks MVVM and lookless control principles as a shadow is entirely a styling choice.

Expected behavior

<Grid>
    <Grid.Resources>
        <ThemeShadow x:Name="SharedShadow" />
    </Grid.Resources>

    <Grid x:Name="BackgroundGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" />

    <Rectangle x:Name="Rectangle1" Height="100" Width="100" Fill="Turquoise" Shadow="{StaticResource SharedShadow}" />

    <Rectangle x:Name="Rectangle2" Height="100" Width="100" Fill="Turquoise" Shadow="{StaticResource SharedShadow}" />
</Grid>

Should produce:

sharedshadow

Without having to add the following in code behind (I realize Translation can already be set in XAML).

SharedShadow.Receivers.Add(BackgroundGrid);

Rectangle1.Translation += new Vector3(0, 0, 16);
Rectangle2.Translation += new Vector3(120, 0, 32);

https://docs.microsoft.com/en-us/windows/uwp/design/layout/depth-shadow

Rationale

Slowly MVVM and lookless control principles are getting broken. We need to maintain the ability to style shadows entirely within XAML. This came up when talking about styling a new control that has a a selected color that should have a drop-shadow effect. The shadow receiver would need to become a template part and registered in code-behind with the current ThemeShadow implementation. It doesn’t make sense that an additional template part should be required for this situation. We need the ability to do things like shadows directly and entirely in XAML:

image

Scope

Capability Priority
Remove the need to register shadow receivers before use or add ability to register in XAML Must

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:21 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
mdtaukcommented, Jun 29, 2020

I never implied either things 😉 I just want to point out that both are a lot of work for limited reward, even if you say that we all need to have lookless controls. In my opinion, ideally, you wouldn’t have to retemplate controls because they are already customizable enough through properties and lightweight styling and only in very specific scenarios a retemplate is needed to get the desired result.

Moving away from Lookless Controls would be a big change (should probably go hand in hand with a wholesale change from Xaml to Xaml Next) - and could be a good thing. But it would not be Xaml in the way it has existed since Avalon and WinXP’s days.

Android and Apple have their own UI paradigms - none as flexible as Xaml for changing control designs - but with Rendering offloaded to GPUs, could there be a call for a new approach - without Xaml trees to parse, but deeper aspects of primitive shapes, shadows, etc?

1reaction
robloocommented, Jul 1, 2020

@michael-hawker Yes, we were definitely getting off track for this issue. Thanks for linking to the relevant one, I didn’t know it already existed and I’ll copy some comments over to it.

I also could have sworn when UWP first released (years ago now) the docs looked very much like WPF for templates. What I remember looks exactly like the WPF docs though so it’s possible I was just confusing the two.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ThemeShadow Class (Windows.UI.Xaml.Media)
A ThemeShadow is a preconfigured shadow effect that can be applied to any XAML element to draw shadows appropriately based on x, y,...
Read more >
UWP | XAML Brewer, by Diederik Krols
In this article we describe the process of migrating a user control from UWP to WinUI 3. The subject is the Radial Gauge...
Read more >
Shadows in Windows (UWP) XAML Applications - Part 1
Shadows using ThemeShadow. Whilst support for shadows has been around for quite a while for UWP applications, it was only recent that the ......
Read more >
How to create ThemeShadow programmatically? (C# UWP ...
I tried to create ThemeShadow programmatically but cannot solve the Resources part in XAML . I call the void like this: CreateTheme(Test ...
Read more >
Elevate your UI with ThemeShadow
A ThemeShadow is a preconfigured shadow effect that can be applied to any XAML element to draw shadows appropriately based on x, y, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found