Take a look at VisualBrush. You can customize the visualization of VisualBrush to the control, and VisualBrush will re-create the visual representation of the control without any real functionality.
I took this example from Sells / Griffiths “WPF Programming” (chapter 13 on the chart) and modified it a bit, and then a bit more to show you the solution.
What this means is to create a simple drawing interface (entering the x and y coordinates from two points to draw a line), but also reflects the image below. It does not have to be reliable, but it has to demonstrate functionality, I think what you are looking for.
The last two elements of the rectangle with VisualBrush and SolidColorBrush are how I create a duplicate control and then shade it.
What you can do is put these 2 elements on the page / window / etc that you want to shade, and then make them visible when you want the effect to take place.
Hope this helps.
<Window x:Class="GraphicsTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Window.Resources> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="2*"/> <RowDefinition Height="1*"></RowDefinition> </Grid.RowDefinitions> <Grid x:Name="mainUI"> <DockPanel> <GroupBox Header="Point 1" Name="gbPoint1" DockPanel.Dock="Top"> <StackPanel Orientation="Horizontal"> <Label Width="40" HorizontalContentAlignment="Right">X:</Label> <TextBox Name="tbX1" Width="40" TextChanged="Content_TextChanged"/> <Label Width="40" HorizontalContentAlignment="Right">Y:</Label> <TextBox Name="tbY1" Width="40" TextChanged="Content_TextChanged"/> </StackPanel> </GroupBox> <GroupBox Header="Point 2" Name="gbPoint2" DockPanel.Dock="Top"> <StackPanel Orientation="Horizontal"> <Label Width="40" HorizontalContentAlignment="Right">X:</Label> <TextBox Name="tbX2" Width="40" TextChanged="Content_TextChanged"/> <Label Width="40" HorizontalContentAlignment="Right">Y:</Label> <TextBox Name="tbY2" Width="40" TextChanged="Content_TextChanged"/> </StackPanel> </GroupBox> <Canvas> <Line Name="lnDraw" Stroke="Black" StrokeThickness="2"/> </Canvas> </DockPanel> </Grid> <Rectangle Grid.Row="1"> <Rectangle.LayoutTransform> <ScaleTransform ScaleY="-1"/> </Rectangle.LayoutTransform> <Rectangle.Fill> <VisualBrush Visual="{Binding ElementName=mainUI}" /> </Rectangle.Fill> </Rectangle> <Rectangle Grid.Row="1"> <Rectangle.Fill> <SolidColorBrush Color="Black" Opacity=".5"/> </Rectangle.Fill> </Rectangle> </Grid>
And .cs
public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void Content_TextChanged(object sender, TextChangedEventArgs e) { int x1; int x2; int y1; int y2; if (int.TryParse(tbX1.Text, out x1) && int.TryParse(tbX2.Text, out x2) && int.TryParse(tbY1.Text, out y1) && int.TryParse(tbY2.Text, out y2)) { lnDraw.X1 = x1; lnDraw.X2 = x2; lnDraw.Y1 = y1; lnDraw.Y2 = y2; } } }
source share