Universal Windows Platform – Shade Effect

Step 1

If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu locate and select Visual Studio 2017.


Step 2

Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…


Step 3

From New Project choose Visual C# from Installed, Templates then choose Blank App (Universal Windows) and then type in a Name and select a Location and then select Ok to create the Project


Step 4

Then in New Universal Windows Project you need to select the Target Version to be Windows 10 Creators Update (10.0; Build 15063) and the Minimum Version to be at least Windows 10 Anniversary Update (10.0; Build 14393) or Windows 10 Creators Update (10.0; Build 15063)


Step 5

In the Solution Explorer select MainPage.xaml


Step 6

From the Menu choose View and then Designer


Step 7

The Design View will be displayed along with the XAML View and in this between the Grid and /Grid elements, enter the following XAML:

<CommandBar IsOpen="True" VerticalAlignment="Bottom">
	<AppBarButton Name="Accept" Icon="Accept" Label="Accept" Click="Accept_Click"/>
	<AppBarButton Name="Clear" Icon="Cancel" Label="Clear" Click="Clear_Click"/>
<Grid Height="300" Width="300">
	<Border x:Name="ShadowElement"/>
	<Path Name="Logo" Fill="#FF68217A" Stretch="Uniform" 
		L27.021,0z M3.592,12.653v10.939l5.388-5.551L3.592,12.653z M17.633,18.041l9.306,7.348V10.693L17.633,18.041z">

It should appear as such:


Step 8

From the Menu choose View and then Code


Step 9

Once in the Code View, below the public MainPage() { … } the following Code should be entered:

private Windows.UI.Composition.SpriteVisual spriteVisual;

private Windows.UI.Composition.Compositor Compositor
		return Windows.UI.Xaml.Hosting.ElementCompositionPreview.GetElementVisual(Logo).Compositor;

private void Accept_Click(object sender, RoutedEventArgs e)
	spriteVisual = Compositor.CreateSpriteVisual();
	spriteVisual.Size = new System.Numerics.Vector2((float)Logo.ActualWidth, (float)Logo.ActualHeight);
	Windows.UI.Composition.DropShadow shadow = Compositor.CreateDropShadow();
	shadow.Color = Windows.UI.Colors.Black;
	shadow.Offset = new System.Numerics.Vector3(10, 10, 0);
	shadow.Mask = Logo.GetAlphaMask();
	spriteVisual.Shadow = shadow;
	Windows.UI.Xaml.Hosting.ElementCompositionPreview.SetElementChildVisual(ShadowElement, spriteVisual);

private void Clear_Click(object sender, RoutedEventArgs e)
	spriteVisual.Shadow = null;

It should then appear as such:


Step 10

That completes the Universal Windows Application so Save the Project then in Visual Studio select the Local Machine to run the Application


Step 11

Once started the Application should then appear


Step 12

After the Application has started running you can then select Accept to enable the Shade Effect or use Clear to remove the effect


Step 13

To Exit the application select Stop in Visual Studio


Creative Commons License

2 thoughts on “Universal Windows Platform – Shade Effect

  1. Thanks for your tutorial! and i found a bug in this code, that if i click cancel first, the app will crush, warning that object reference not set to an instance of an object.
    so i try to fix it on my own, finally i rewrite the function “clear_click”as following:

    private void Clear_Click(object sender, RoutedEventArgs e)
    if (pointLight != null)

    and then it works.

    finally thx again!


    • Indeed, should be a null-check there – think I caught this during pre-production of these tutorials (yes the light effect would have the same bug) but I can’t recall if the bug was left intentionally as an exercise or not but either way I’ll fix this one as it’s quite an obvious omission!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s