问题描述
有很多教程,告诉你如何使用WPF应用程序Vista的玻璃效果如之一。
我不想用默认的颜色主题,用户选择。换句话说,如果我申请了Vista的玻璃效应到我的WPF应用程序将是等于无论用户选择:
这是我已经尝试,它是有些一个解决方案:
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
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:
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
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.
这篇关于创建与自定义颜色WPF Vista的玻璃效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!