- .NET Standard 2.0 Cookbook
- Fiqri Ismail
- 443字
- 2021-06-25 22:11:32
How to do it...
- Open Visual Studio 2017.
- Now open the solution from the previous recipe. Click File | Open | Open Project/Solution, or press Ctrl + Shift + O, and select the Chapter1.Library solution.
- Now click on the Chapter1.Library solution label. Click File | Add | New Project.
- In the Add New Project template dialog box, expand the Visual C# node in the left-hand pane.
- Select Windows Classic Desktop and select WPF App (.NET Framework) in the right template pane.

- Now, in the Name: text box, type a name for the new project. Let's type Chapter1.Library.HelloWPF and leave the Location: as it is and the defaults as well. Click OK to create the new project.

- Now the Solution Explorer (if it's not visible, press Ctrl + Alt + L) should look like this:

- Now click on the MainWindow.xaml tab and make sure you are in the Design mode.
- Now, drag and drop a Button and a TextBlock from the tool box (to view the tool box, press Ctrl + Alt + X). You can find these components under Common WPF Controls.
- The main window should look like this:

- Let's name our controls and change some properties as follows:
- Let's add our class library as a reference to the WPF project we have just created. Expand the Chapter1.Library.HelloWPF project node and expand the References node in the Solution Explorer (if you don't see the Solution Explorer press Ctrl + Alt + L).
- Right-click on the References label and select Add Reference....
- Under the Reference Manager dialog box, click on the Projects label in the left-hand pane. In the middle pane, check the Chapter1.Library.HelloLib project:

- Click OK.
- In the MainWindow.xaml tab, double-click on the SayHello button.
- In the MainWindow.xamal.cs tab, scroll up till you see the using code block. Add this code as the last line of the using code block:
using Chapter1.Library.HelloLib;
- Now scroll down till you reach the HelloButton_Click method. Type the following code block in between the curly brackets of the HelloButton_Click method:
var yourName = "Fiqri Ismail";
var helloMessage = new HelloWorld();
MessageLabel.Text = helloMessage.SayHello(yourName);
- Now we are ready to test. Press F5 to debug our code:

- Click on the Say Hello button to see the message from the class library:

- Congratulations!!! You have just used a library created with a WPF application.
推薦閱讀
- 深入核心的敏捷開發(fā):ThoughtWorks五大關(guān)鍵實(shí)踐
- Java入門經(jīng)典(第6版)
- 兩周自制腳本語言
- Vue.js前端開發(fā)基礎(chǔ)與項(xiàng)目實(shí)戰(zhàn)
- TestNG Beginner's Guide
- 64位匯編語言的編程藝術(shù)
- Java:Data Science Made Easy
- Spring實(shí)戰(zhàn)(第5版)
- Instant RubyMotion App Development
- 名師講壇:Spring實(shí)戰(zhàn)開發(fā)(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- 可解釋機(jī)器學(xué)習(xí):模型、方法與實(shí)踐
- 精通Linux(第2版)
- Mastering Akka
- Scratch趣味編程:陪孩子像搭積木一樣學(xué)編程
- Fast Data Processing with Spark(Second Edition)