- .NET Standard 2.0 Cookbook
- Fiqri Ismail
- 458字
- 2021-06-25 22:11:38
How it works...
Now we have a working WPF application that uses a .NET Standard 2.0 library as its source. Let's have a look at the steps we followed. In steps 1 to 7, we opened the previously built .NET Standard 2.0 library project and the solution. After that, we added a Windows Presentation Foundation project to the solution. As you know, WPF is a UI framework that runs on top of the .NET Framework.
From steps 9 to 13, we just created the user interface for our application. Then, in step 12, we changed some default properties of the controls we added. Giving meaningful names is a very good practice as it helps you to build readable code. In step 20, we just double-clicked on a control, in this case the button, to open the code windows. By default, Visual Studio chooses an event for us. Mainly, it chooses a commonly used event and, in this case, it's the click event of the button.
In step 22, we referenced the .NET Standard 2.0 library to the code. This will allow you to access its available methods in the WPF application. In step 23, we have the actual running code for the button click event. In the first line, we created an instance of LittleShop() and stored it in a variable. Then we used the GetFruitsList() method to get the list of fruits and stored it in a variable. Then we looped through all the available items in the fruits variable.
foreach (var fruit in fruits)
{
FruitsList.Items.Add(fruit);
}
In the previous code for the fruits variable, there is a List collection. foreach will loop through each item inside the List collection stored in the fruits variable. And inside the loop, a FruitsList list box control adds each item in the fruits collection, which is stored in the fruit variable.
FruitsList.Items.Add("--------");
FruitsList.Items.Add($"Item Count: {fruits.Count}");
FruitsList.Items.Add($"Capacity: {fruits.Capacity}");
After we have added each item to the list box (FruitsList), we have added a string that displays the number of items in the List collection. We have used the Count property in the List collection to get that information. And, in the last line of code, we picked the Capacity of the List collection. The capacity property gets or sets the total number of elements the internal data structure can hold without resizing.
In step 26, we created an instance of the LittleShop() class and used the GetShopItems() method to get the items returned as an ArrayList(). Then we used a for loop to get the items inside the second list box. The rest is the same as we did with the List collection.
- Android應(yīng)用程序開發(fā)與典型案例
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- INSTANT Sencha Touch
- Swift 3 New Features
- CouchDB and PHP Web Development Beginner’s Guide
- 軟件工程
- 程序員修煉之道:通向務(wù)實(shí)的最高境界(第2版)
- PLC編程與調(diào)試技術(shù)(松下系列)
- Learning OpenStack Networking(Neutron)(Second Edition)
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第二版)
- QGIS 2 Cookbook
- C++ System Programming Cookbook
- Learning Concurrency in Python
- ASP.NET開發(fā)寶典
- Three.js權(quán)威指南:在網(wǎng)頁上創(chuàng)建3D圖形和動(dòng)畫的方法與實(shí)踐(原書第4版)