1、添加用于启动的类Program.cs,需要一个静态的Main函数入口。
using System;
using System.Windows;
using System.Windows.Controls;
棕色部分实现窗口的位置固定和跟随。
public class Program
{
private static Application _MainApplication;
internal static Application MainApplication
{
get { return _MainApplication ?? (_MainApplication = new Application()); }
}
[STAThread]
public static void Main(string[] args)
{
var MainWin = new Window();
var FollowWin = new Window();
//拉姆达表达式
MainWin.Loaded +=
(s, e) =>
{
FollowWin.WindowStartupLocation = WindowStartupLocation.Manual;
FollowWin.Left = MainWin.Left + MainWin.Width;
FollowWin.Top = MainWin.Top;
FollowWin.Show();
};
//当窗口位置更改时发生
MainWin.LocationChanged +=
(s, e) =>
{
FollowWin.Left = MainWin.Left + MainWin.Width;
FollowWin.Top = MainWin.Top;
};
MainApplication.ShutdownMode = ShutdownMode.OnExplicitShutdown;
MainApplication.Run(touch);
}
}
2、设置类库项目的输出类型为“Windows应用程序”:
3、设置启动对象为第一步中创建的Program
4、运行即可。