标签:edit ase views public 静态 stat 需要 blog led
原文:WPF 设置类库项目为启动项,设置窗体跟随。
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、运行即可。
标签:edit ase views public 静态 stat 需要 blog led
原文地址:https://www.cnblogs.com/lonelyxmas/p/9547400.html