這是(測試的)解決方案。此代碼可以用於WinForm或WPF應用程序。 根本不需要XAML。
#region WPF
// include following references:
// PresentationCore
// PresentationFramework
// WindowsBase
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
#endregion
public class WPFWindow : Window
{
private Canvas canvas = new Canvas();
public WPFWindow()
{
this.AllowsTransparency = true;
this.WindowStyle = WindowStyle.None;
this.Background = Brushes.Black;
this.Topmost = true;
this.Width = 400;
this.Height = 300;
canvas.Width = this.Width;
canvas.Height = this.Height;
canvas.Background = Brushes.Black;
this.Content = canvas;
}
}
窗口背景是完全透明的。 您可以在畫布上繪圖,並且每個元素都可以具有自己的透明度(您可以通過設置用於繪製畫筆的畫筆的Alpha通道來確定)。 簡單的東西調用的窗前,彷彿
WPFWindow w = new WPFWindow();
w.Show();
,看一下我的回答是:http://stackoverflow.com/questions/8311956/open-wpf-window-in-windowsform-app/32691690#32691690 – 2015-09-21 10:00:55