Many times I want to make my WPF Controls have a 3D effect. For examples Headers of lists and such. Saddly there is no built in way to do it so we have to come up with a custom solution. I don’t want to use Bitmap effects due to performance reasons, I must say I don’t have much experience with them but from what I have I am not a big fan.
Here is my solution for a 3D effect on WPF Controls.
First of all a Quick demonstration. Which one looks better.
I don’t know about you but the second one is much nicer with that 3D effect.
How is it done? As I said before I don’t like using Bitmap effects if I don’t have to, so this is done with combining 2 borders together. The simple upper one is a regular border with TextBlock
Usually, the WPF controls are declared in the .xaml file and not in the code behind (.xaml.cs file). However, we might need to use some of those controls in the code behind in order to manipulate them. How can we get the handle of such a control if it “resides” in the xaml file? Take a look at the following xaml code:
<Window x:Class="WpfApplication2.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" MouseLeftButtonDown="window_Clicked"> <Grid> <TextBlock x:Name="fullNameControl" FontSize="20" Text="{Binding Path=FullName}"> </TextBlock> </Grid> </Window>
There is a TextBlock called fullNameControl, in the code behind I change its background color to gold when the window is clicked:
We all know the propertyGrid control, which provides a user interface for browsing the properties of an object. What about having a WPF propertyGrid? Well, yesterday I noticed that there is a work in progress on an open source WPF property grid. Tomer Shamam announced in his blog Essential WPF that he accepted Microsoft Israel OPEN UP challenge (open source contest) and created a new project - WPF property grid. As he stated, it is currently only a Proof of concept and the interface and its usage may change in next releases. I think that its worth tracking…