I have a set of transforms that I apply to make a fancy reflection for controls. I want to be able to apply the same stuff to other elements, but I don’t know how to group it together, and apply it as a resource.
Can someone help me? Here is some code, this applies the transform to the first textbox. It looks a lot but is pretty simple, it is just a rectangle under a control, with a few transforms and other visual effects applied. What I want is to do the same with this rectangle but apply it to other controls (and so somehow parameterize the bindings.)
<StackPanel Margin="40">
<TextBlock x:Name="TitleDisp" FontSize="40" FontFamily="Verdana" Opacity="0.8" HorizontalAlignment="Center">Sample Title</TextBlock>
<Rectangle Height="{Binding Path=ActualHeight, ElementName=TitleDisp}" Width="{Binding Path=ActualWidth, ElementName=TitleDisp}">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=TitleDisp}"/>
</Rectangle.Fill>
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.75"/>
<SkewTransform AngleX="10" AngleY="8"/>
<TranslateTransform X="30" Y="-10"/>
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.OpacityMask>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Offset="0" Color="Transparent"/>
<GradientStop Offset="1" Color="#77000000"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.Effect>
<BlurEffect/>
</Rectangle.Effect>
</Rectangle>
</StackPanel>
I think
Adornersare what you are looking for here. They render on top of the controls in their own layer, and you can adorn any UIElement you wish, in your case you would be adorning the textbox with the rectangle that has those properties defined. The MSDN article on Adorners is a good start and it is a pretty easy read.