using a DrawingBrush resource for a Grid Background - wpf

I am trying to set the background of a UniformGrid to a DrawingBrush resource and I am getting an error. How do I do this:
<UniformGrid Rows="1" Columns="1" Height="75" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Grid.Row="2">
<UniformGrid.Background>
<DrawingBrush="{StaticResource SteelBrush_Vert}"/>
</UniformGrid.Background>
Error: White Space is missing
This is the Steel_Brsh_Vert I am trying to use:
<DrawingBrush x:Key="SteelBrush_Vert" Stretch="Fill">
<DrawingBrush.Drawing >
<DrawingGroup>
<GeometryDrawing Geometry="M114.000,293.847C114.000,280.324,114.045,269.362,114.100,269.362L391.900,269.362C391.955,269.362,392.000,280.324,392.000,293.847L392.000,485.878C392.000,499.400,391.955,510.362,391.900,510.362L114.100,510.362C114.045,510.362,114.000,499.400,114.000,485.878z">
<GeometryDrawing.Brush>
<LinearGradientBrush StartPoint="114,389.862" EndPoint="392,389.862" MappingMode="Absolute" SpreadMethod="Pad">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="#FFDADADA" Offset="0.082" />
<GradientStop Color="#FF282828" Offset="0.854" />
<GradientStop Color="White" Offset="0.949" />
<GradientStop Color="Black" Offset="1" />
</LinearGradientBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
<DrawingBrush.RelativeTransform>
<RotateTransform CenterX=".5" CenterY=".5" Angle="90"/>
</DrawingBrush.RelativeTransform>
</DrawingBrush>

You can use the Background property inline with the UniformGrid.
Try the code below:
<UniformGrid Background="{StaticResource SteelBrush_Vert}"
Rows="1"
Columns="1"
Height="75" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Grid.Row="2"/>

Related

How do I add this ellipse template to my button border?

I'm aware there are probably similar questions to this one but I have no idea how to sort this out. I'm rather new to XAML and have written the following:
<Window.Resources>
<ControlTemplate x:Key="ButtonTemplate">
<Ellipse Height="300" StrokeThickness="2" Width="300" >
<Ellipse.Fill>
<SolidColorBrush Color="white" Opacity="0"/>
</Ellipse.Fill>
<Ellipse.Stroke>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="Red" Offset="0.1"/>
<GradientStop Color="Orange" Offset="0.35"/>
<GradientStop Color="SeaGreen" Offset="0.7"/>
<GradientStop Color="DarkBlue" Offset="0.95"/>
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
</ControlTemplate>
</Window.Resources>
<Grid>
<Button Height="320" Width="320" Margin="200,100,200,100" Background="White" BorderThickness="0">
<Button.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Crimson" Offset="0.1" />
<GradientStop Color="SeaGreen" Offset="0.9" />
</LinearGradientBrush>
</Button.Foreground>
<Button.Content>
<TextBlock FontSize="30">TEST BUTTON</TextBlock>
</Button.Content>
</Button>
</Grid>
Putting the circle in a template seems to be the universally agreed way to start going about getting a circular border on the button, but nothing seems to work from there for me. I've left the template disconnected from the button here because it doesn't work, rather it seems to just overlay a solid circle on top of what is otherwise a working button. Can someone help me out?
You should specify the TargetType and add a ContentPresenter to the ControlTemplate:
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Grid>
<Ellipse Height="300" StrokeThickness="2" Width="300" >
<Ellipse.Fill>
<SolidColorBrush Color="White" Opacity="0"/>
</Ellipse.Fill>
<Ellipse.Stroke>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="Red" Offset="0.1"/>
<GradientStop Color="Orange" Offset="0.35"/>
<GradientStop Color="SeaGreen" Offset="0.7"/>
<GradientStop Color="DarkBlue" Offset="0.95"/>
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
<ContentPresenter Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
And don't forget to apply the custom template by setting the Template property of the Button:
<Button Height="320" Width="320" Background="White" BorderThickness="0"
Template="{StaticResource ButtonTemplate}">
<Button.Foreground>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Crimson" Offset="0.1" />
<GradientStop Color="SeaGreen" Offset="0.9" />
</LinearGradientBrush>
</Button.Foreground>
<Button.Content>
<TextBlock FontSize="30">TEST BUTTON</TextBlock>
</Button.Content>
</Button>

WPF enabling transparency

Going off the how-to from MSDN here, I have the following code that displays a reflection right below an element.
How can I enable transparency on the reflection only, so what is behind the window shows through the reflection?
<Window x:Class="XAMLViewTests.AboutWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AboutWindow" ResizeMode="CanResizeWithGrip" SizeToContent="WidthAndHeight" Width="400"
AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterOwner" Background="Transparent">
<Window.Resources>
<Style TargetType="TextBlock" x:Key="formattedText">
<Setter Property="FontFamily" Value="Calibri"></Setter>
<Setter Property="FontSize" Value="20"></Setter>
<Setter Property="Padding" Value="5,5,5,5"></Setter>
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
<LinearGradientBrush x:Key="linearGradBrush">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0"
Color="White"></GradientStop>
<GradientStop Offset="1.0"
Color="LightSlateGray"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Window.Resources>
<StackPanel Orientation="Vertical" Background="{StaticResource linearGradBrush}">
<Button Width="50" HorizontalAlignment="Right" Click="ReturnToPreviousWindow" Background="White">Return</Button>
<TextBlock Style="{StaticResource formattedText}" x:Name="textBlock" HorizontalAlignment="Center">
Some text here.
</TextBlock>
<!-- Reflection visual courtesy of MS How-To at https://msdn.microsoft.com/en-us/library/aa970263(v=vs.110).aspx -->
<Rectangle Height="1" Fill="Gray" HorizontalAlignment="Stretch"></Rectangle>
<Rectangle Height="{Binding ElementName=textBlock, Path=ActualHeight}"
Width="{Binding ElementName=textBlock, Path=ActualWidth}"
HorizontalAlignment="{Binding ElementName=textBlock, Path=HorizontalAlignment}">
<Rectangle.Fill>
<VisualBrush Stretch="None" Visual="{Binding ElementName=textBlock}">
<VisualBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="-1"></ScaleTransform>
<TranslateTransform Y="1"></TranslateTransform>
</TransformGroup>
</VisualBrush.RelativeTransform>
</VisualBrush>
</Rectangle.Fill>
<Rectangle.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FF000000" Offset="0.0"></GradientStop>
<GradientStop Color="#33000000" Offset="0.5"></GradientStop>
<GradientStop Color="#00000000" Offset="0.9"></GradientStop>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.Effect>
<BlurEffect Radius="2.5"></BlurEffect>
</Rectangle.Effect>
</Rectangle>
</StackPanel>
</Window>
The linear gradient brush has 100% opacity and is applied to the entire stackpanel which contains the element you want transparency on. I reformatted it a bit and split out the stackpanel. Probably needs more work, but this should demonstrate the concept. Note the second gradient brush with a 0.5 (50%) opacity applied to the second stackpanel.
<Window x:Class="XAMLViewTests.AboutWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AboutWindow" ResizeMode="CanResizeWithGrip" SizeToContent="WidthAndHeight" Width="400"
AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterOwner" Background="Transparent">
<Window.Resources>
<Style TargetType="TextBlock" x:Key="formattedText">
<Setter Property="FontFamily" Value="Calibri"></Setter>
<Setter Property="FontSize" Value="20"></Setter>
<Setter Property="Padding" Value="5,5,5,5"></Setter>
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
<LinearGradientBrush x:Key="linearGradBrush">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0"
Color="White"></GradientStop>
<GradientStop Offset="1.0"
Color="LightSlateGray"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="linearGradBrushWithTransparency" Opacity="0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0"
Color="White"></GradientStop>
<GradientStop Offset="1.0"
Color="LightSlateGray"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Window.Resources>
<StackPanel Orientation="Vertical" Background="{StaticResource linearGradBrushWithTransparency}">
<StackPanel Orientation="Vertical" Background="{StaticResource linearGradBrush}">
<Button Width="50" HorizontalAlignment="Right" Click="ReturnToPreviousWindow" Background="White">Return</Button>
<TextBlock Style="{StaticResource formattedText}" x:Name="textBlock" HorizontalAlignment="Center">
Some text here.
</TextBlock>
<!-- Reflection visual courtesy of MS How-To at https://msdn.microsoft.com/en-us/library/aa970263(v=vs.110).aspx -->
<Rectangle Height="1" Fill="Gray" HorizontalAlignment="Stretch"></Rectangle>
</StackPanel>
<Rectangle Height="{Binding ElementName=textBlock, Path=ActualHeight}"
Width="{Binding ElementName=textBlock, Path=ActualWidth}"
HorizontalAlignment="{Binding ElementName=textBlock, Path=HorizontalAlignment}"
Opacity=".5">
<Rectangle.Fill>
<VisualBrush Stretch="None" Visual="{Binding ElementName=textBlock}">
<VisualBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="-1"></ScaleTransform>
<TranslateTransform Y="1"></TranslateTransform>
</TransformGroup>
</VisualBrush.RelativeTransform>
</VisualBrush>
</Rectangle.Fill>
<Rectangle.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FF000000" Offset="0.0"></GradientStop>
<GradientStop Color="#33000000" Offset="0.5"></GradientStop>
<GradientStop Color="#00000000" Offset="0.9"></GradientStop>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.Effect>
<BlurEffect Radius="2.5"></BlurEffect>
</Rectangle.Effect>
</Rectangle>
</StackPanel>
</Window>

How do I create repeating diagonal lines as a background in WPF?

OK, I've wracked my brain, Google, and stackoverflow trying to figure this out, but just can't quite get it. I'm trying to use a DrawingBrush with a DrawingGroup to do two things to the background of my WPF application (latest version). One, I want to have a RadialGradientBrush to put a subtle gradient in my background. This part is working just fine. The second part that I'm trying to accomplish is that I want to also have repeating diagonal lines as part of that background. I know I could do it with an image, but would rather use geometries, as I'm trying to learn and master WPF. Here's what I have so far. The radial appears fine, but the lines do not. Any help would be appreciated.
<Style x:Key="WindowBackground" TargetType="Grid">
<Setter Property="Background">
<Setter.Value>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing>
<GeometryDrawing.Brush>
<RadialGradientBrush GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
<GradientStop Color="#EE9D40" Offset="0"/>
<GradientStop Color="#BF8230" Offset="1"/>
</RadialGradientBrush>
</GeometryDrawing.Brush>
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,1,1"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing>
<GeometryDrawing.Brush>
<DrawingBrush TileMode="Tile" Stretch="None" Viewbox="0,0,1,1" Viewport="0,0,25,25" ViewportUnits="Absolute">
<DrawingBrush.RelativeTransform>
<TranslateTransform X="0" Y="0" />
</DrawingBrush.RelativeTransform>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="#20FFFFFF" Geometry="M10,0 22,0 12,25 0,22 Z" />
</DrawingBrush.Drawing>
</DrawingBrush>
</GeometryDrawing.Brush>
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,1,1"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Setter.Value>
</Setter>
</Style>
This trick should work.
<LinearGradientBrush EndPoint="0,0" StartPoint="8,8"
MappingMode="Absolute" SpreadMethod="Repeat">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="Black" Offset="0.1" />
<GradientStop Color="White" Offset="0.1" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
Try rotating a horizontal line brush to avoid the corner gaps:
<VisualBrush TileMode="Tile"
Viewport="0,0,5,5" ViewportUnits="Absolute"
Viewbox="0,0,5,5" ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Grid Background="White" Height="5">
<Path Stroke="Black" Data="M 0 3 l 8 0" />
</Grid>
</VisualBrush.Visual>
<VisualBrush.RelativeTransform>
<RotateTransform CenterX="0.5" CenterY="0.5" Angle="45" />
</VisualBrush.RelativeTransform>
</VisualBrush>
I finally got it working, but not with a single composite brush like I was wanting. I used the following styles:
<Style x:Key="WindowBackground" TargetType="Grid">
<Setter Property="Background">
<Setter.Value>
<RadialGradientBrush GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5">
<GradientStop Color="#EAA659" Offset="0"/>
<GradientStop Color="#BF8230" Offset="1"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HatchOverlay" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<VisualBrush Opacity=".1" TileMode="Tile" Viewport="0,0,10,20" ViewportUnits="Absolute">
<VisualBrush.Visual>
<Canvas>
<Path Stroke="#825821" Data="M 0 0 l 10 20" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
Then, to enable it at run time, I added a rectangle as the first child of my grid, like so:
<Grid Style="{StaticResource WindowBackground}">
<Rectangle Style="{StaticResource HatchOverlay}"/>...
This gave me the effect that I was after. Thanks for your help; I'll up-vote each of you.

Custom grid style in Silverlight 4

I want to set background of a grid using a style. I style I'm setting the Background Property of the grid.
But I have a border filled with LinearGradientFill and a Path which also has LinearGradientFill in it.
But I'm not able to combine both.
Below is sample code. I want to create it as a style.
<Grid>
<Border BorderBrush="Black" BorderThickness="2">
<Border.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="Black" Offset="0.953" />
<GradientStop Color="White" Offset="0" />
</LinearGradientBrush>
</Border.Background>
</Border>
<Path Data="M 0,0 C 0,620 10,10 560,0" Height="60" VerticalAlignment="Top">
<Path.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="White" Offset="0.779" />
</LinearGradientBrush>
</Path.Fill>
</Path>
</Grid>
It gives me an error as:
The Property 'Value' is set more than once.
Archie,
You need to use a Template in order to place arbitrary XAML into a Style. Unfortuately, only Controls have Templates, and Grids and Borders are not Controls. But there is a solution. Although not as clean as you would like, the following XAMl should accomplish your goal. You paste the following XAML into Charles Petzold's XAML Cruncher to see the results:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="400">
<UserControl.Resources>
<!-- A ContentControl template that defines your background -->
<ControlTemplate x:Key="BackgroundTemplate" TargetType="ContentControl">
<Grid>
<Border BorderBrush="Black" BorderThickness="2">
<Border.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="Black" Offset="0.953" />
<GradientStop Color="White" Offset="0" />
</LinearGradientBrush>
</Border.Background>
</Border>
<Path Data="M 0,0 C 0,620 10,10 560,0" Height="60" VerticalAlignment="Top">
<Path.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="White" Offset="0.779" />
</LinearGradientBrush>
</Path.Fill>
</Path>
</Grid>
</ControlTemplate>
<!-- A ContentControl Style that references the background template -->
<Style x:Key="BackgroundStyle" TargetType="ContentControl">
<Setter Property="Template" Value="{StaticResource BackgroundTemplate}" />
</Style>
</UserControl.Resources>
<!-- Typical usage; place the background ContentControl behind your body content -->
<Grid x:Name="LayoutRoot">
<ContentControl Style="{StaticResource BackgroundStyle}" />
<TextBlock Text="Your Content" Foreground="Red" FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</UserControl>

How to draw a drop-shadow on a transparent rectangle?

When I add a dropshadow bitmap effect to a rectangle, the dropshadow takes into account the transparency of the rectangle (makes sense). Is there a way to render a dropshadow on a transparent rectangle 'as if' the rectangle were opaque? ie what would appear is a rectangle-shaped 'hole', with a dropshadow.
Here is the XAML for a transparent rectangle with a dropshadow - nothing is displayed:
<Rectangle Fill="Transparent" Margin="10" Width="100" Height="100">
<Rectangle.BitmapEffect>
<DropShadowBitmapEffect/>
</Rectangle.BitmapEffect>
</Rectangle>
Drop this into Kaxaml. It creates a transparent Rectangle of size 500x500, with a SystemDropShadowChrome Decorator. The drop shadow's clip is set to exclude the Rectangle's region.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas>
<theme:SystemDropShadowChrome Margin="0,0,5,5">
<Rectangle Width="500" Height="500" Fill="transparent"/>
<theme:SystemDropShadowChrome.Clip>
<CombinedGeometry GeometryCombineMode="Exclude">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0,0,505,505"/>
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<RectangleGeometry Rect="0,0,500,500"/>
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</theme:SystemDropShadowChrome.Clip>
</theme:SystemDropShadowChrome>
</Canvas>
</Page>
If you want your drop shadow to have rounded corners, then set the CornerRadius of the SystemDropShadowChrome to whatever (let's say 10), then Geometry1's Left and Top values to 10, then the RadiusX and RadiusY of each RectangleGeometry to 10.
I'd love to see better solution, but here is what I usually do (beware: creepy code ahead).
Wrap rectangle to three-four rectangles, and play with stroke color, making it darker and darker as it goes to original rectangle. Here is the code:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Rectangle
Width="106"
Height="106"
Stroke="#10000000"
StrokeThickness="1"/>
<Rectangle
Width="104"
Height="104"
Stroke="#5C000000"
StrokeThickness="1"/>
<Rectangle
Width="102"
Height="102"
Stroke="#AC000000"
StrokeThickness="1"/>
<Rectangle
Width="100"
Height="100"
Fill="Transparent"
Stroke="#FF000000"
StrokeThickness="1">
</Rectangle>
</Grid>
</Page>
This gives you:
alt text http://img521.imageshack.us/img521/7664/shadowo.jpg
Another approach would be with borders - it's better because you don't have to specify dimensions, when you put them inside Grid.
And the best approach (never seen implemented though): custom pixel shader, which makes what you want.
Well, here is one long-winded way to implement a rectangular 'drop-shadow' without using a bitmap effect. In this case the centre of the 'shadow rectangle' is coloured in, but it could be set to transparent to give you a 'halo' style drop shadow (i.e., equal all the way round - not offset)
<UserControl x:Class="RectShadow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib">
<UserControl.Resources>
<System:Double x:Key="CornerSize">5</System:Double>
<Color x:Key="ShadowColor">#60000000</Color>
<Color x:Key="TransparentColor">#00000000</Color>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Rectangle Width="{StaticResource CornerSize}" Height="{StaticResource CornerSize}">
<Rectangle.Fill>
<RadialGradientBrush Center="1,1" GradientOrigin="1,1" RadiusX="1" RadiusY="1">
<GradientStop Color="{StaticResource ShadowColor}"/>
<GradientStop Offset="1" Color="{StaticResource TransparentColor}"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="2" Grid.Column="2" Width="{StaticResource CornerSize}" Height="{StaticResource CornerSize}">
<Rectangle.Fill>
<RadialGradientBrush Center="0,0" GradientOrigin="0,0" RadiusX="1" RadiusY="1">
<GradientStop Color="{StaticResource ShadowColor}"/>
<GradientStop Offset="1" Color="{StaticResource TransparentColor}"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="0" Grid.Column="2" Width="{StaticResource CornerSize}" Height="{StaticResource CornerSize}">
<Rectangle.Fill>
<RadialGradientBrush Center="0,1" GradientOrigin="0,1" RadiusX="1" RadiusY="1">
<GradientStop Color="{StaticResource ShadowColor}"/>
<GradientStop Offset="1" Color="{StaticResource TransparentColor}"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="2" Grid.Column="0" Width="{StaticResource CornerSize}" Height="{StaticResource CornerSize}">
<Rectangle.Fill>
<RadialGradientBrush Center="1,0" GradientOrigin="1,0" RadiusX="1" RadiusY="1">
<GradientStop Color="{StaticResource ShadowColor}"/>
<GradientStop Offset="1" Color="{StaticResource TransparentColor}"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Column="1">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Offset="1" Color="{StaticResource ShadowColor}"/>
<GradientStop Color="{StaticResource TransparentColor}"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Column="1" Grid.Row="2">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{StaticResource ShadowColor}"/>
<GradientStop Offset="1" Color="{StaticResource TransparentColor}"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="1">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1,0">
<GradientStop Offset="1" Color="{StaticResource ShadowColor}"/>
<GradientStop Color="{StaticResource TransparentColor}"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="1" Grid.Column="2">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1,0">
<GradientStop Color="{StaticResource ShadowColor}"/>
<GradientStop Offset="1" Color="{StaticResource TransparentColor}"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Grid.Row="1" Grid.Column="1">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource ShadowColor}"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</UserControl>
wrap the rectangle in a border. and add a shadow to the border. you'll get the same effect.

Resources