Original: WPF sets the class library project as a startup item and sets the form to follow.
1. To add the class Program.cs for startup, a static main function entry is required.
using System;using System.Windows;using System.Windows.Controls;
The brown part implements the position of the window fixed and follows.
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 ();//lambda expression mainwin.loaded + = (s, e) + = {Followwin.windo Wstartuplocation = windowstartuplocation.manual; Followwin.left = Mainwin.left + mainwin.width; Followwin.top = Mainwin.top; Followwin.show (); }; //Occurs when the window position changes mainwin.locationchanged + = (s, e) + = {Fol Lowwin.left = Mainwin.left + mainwin.width; Followwin.top = Mainwin.top; };Mainapplication.shutdownmode = Shutdownmode.onexplicitshutdown; Mainapplication.run (Touch); } }
2. Set the output type of the class library project to "Windows Application":
3. Set the Startup object to the program created in the first step
4, the operation can be.
The WPF Settings Class Library project is a startup item, which sets the form to follow.