Create vista glass effect on wpf with custom color

Go To StackoverFlow.com

0

There are a lot of tutorials that show you how to use vista glass effect in wpf application like this one.

I don't want to use the default color theme that the user selects. In other words if I apply the vista glass efect to my wpf application it will be equal to whatever the user selects in:

enter image description here


This is what I have tried and it is somewhat of a solution:

1) get a picture of the entire desktop. I will later figure out how to do this with code

2) place the image in a canvas. I happen to have outlook open when I took the capture of my desktop. Also place a rectangle on top with the color that you want to use with some transparency

enter image description here

3) Create the properties X and Y, implement the INotifyPropertyChanged interface so that we may update the position of the image in code behind:

public partial class MainWindow : Window, INotifyPropertyChanged
{
    double _X;
    public double X
    {
        get
        {
            return _X;
        }
        set
        {
            _X = value;
            NotifyPropertyChanged("X");
        }
    }

    double _Y;
    public double Y
    {
        get
        {
            return _Y;
        }
        set
        {
            _Y = value;
            NotifyPropertyChanged("Y");
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

Dont forget to set: this.DataContext = this; in order to succesfuly bind the properties when the window is done loading

4) Now we need to place the image with position relative to the desktop not to the window. So we create an event handler whenever the window moves we fix the position of the image like:

void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = this;

        this.LocationChanged += new EventHandler(MainWindow_LocationChanged);

    }

    void MainWindow_LocationChanged(object sender, EventArgs e)
    {
        X = -((System.Windows.Window)(sender)).RestoreBounds.TopLeft.X;
        Y = -((System.Windows.Window)(sender)).RestoreBounds.TopLeft.Y;            
    }

Finally you should have something like:

enter image description here

This solution will work great if I where to have an image of the entire desktop. Every time the desktop changes I will have to update the image source. Also when updating the image source I will have to capture the desktop image without my window. I don't know how to get an image of the desktop without my main window. Maybe I will have to hide my window get the screen capture and then show my window again

2012-04-04 04:10
by Tono Nam
Don't do this, its bad for usability. Your user expects a certain behaviour and they have selected a theme they like. do not try and create your own window style and always use what the user expects - Stuart 2012-04-04 17:25
I don't really understand what you're trying to do here.. - BoltClock 2012-04-04 17:27
I am just trying to use the Aero glass effect that vista has on my window using my own color not the one that the user selects in windows. That's why my window has a black border because I have a dark theme... - Tono Nam 2012-04-04 17:31
In this question: http://stackoverflow.com/questions/1464664/changing-the-colour-of-aero-glass-for-my-window someone is trying to override the color. In this question I want to implement it.. - Tono Nam 2012-04-04 17:35


1

If you want a semi-transparent window in WPF, just set the windows Opacity to something < 1, set AllowsTransparency to true and, unfortunately, you have to set WindowStyle to None as well. This means you'll have to recreate the window chrome if you want it.

2012-04-04 17:24
by Matt Burland
Yeah but Aero theme in vista blurs the content in the background. Making the window transparent and placing a background with opacity = .5 will not blur the background - Tono Nam 2012-04-04 17:27
Ads