有些程式有獨特的風格,例如透明應用程式就是一例。那要如何寫出這類風格的程式呢?
Xaml
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" AllowsTransparency="True" WindowStyle="None"
Background="Transparent" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid>
<Ellipse Opacity="0.5" Fill="Green">
<Ellipse.BitmapEffect>
<DropShadowBitmapEffect />
</Ellipse.BitmapEffect>
</Ellipse>
</Grid>
</Window>
重點
- Window 的 AllowsTransparency 必須設為 True,否則無法呈現透明。
- Window 的 WindowStyle 必須設為 None。否則會出現例外。
- Window 的 Background 必須設為 Transparent,以顯示透明效果。
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
這樣,我們就可以拖動視窗了。範例執行畫面如下。
沒有留言:
張貼留言