The first WPF application, the wpf Application

Source: Internet
Author: User

The first WPF application, the wpf Application
WPF is called Windows Presentation Foundation.Core features:

2. New Data banding makes development easier

3. The interface is completely separated from the code for easy maintenance. 4. The interface effect is more dazzling and the user experience is better. Prospects:

1. With the emergence of win8, Microsoft began to marginalized WPF/SilverLight and held HTML5.

2. However, WPF is a good choice for convenient and quick desktop application development on Windows. At the same time, Win8 style applications also support XAML.

Introduction to The XAML language:1. compile the WPF program and ASP.. NET program, but you must first use the XAML to define the program interface, and then use it. NET (VB, C #) language to write the corresponding logic code, the two will work together, and ASP.. NET front-end must be displayed in HTML. 2. in short, WPF: 3. program Interface: Custom XAML Language 4. program Logic: C # Language Implementation 5. in fact, XAML is not a new language, but a new XML-based descriptive language. Its work is similar to HTML in ASP. NET, that is, it customizes all interface elements to form a WPF-style interface. It is the descriptive language used to describe the program UI. 6. although the interface can be implemented using program code in the traditional way, the interface design and logic design can be completely separated by using XAML for design, this allows the business logic design and interface design in the project development to be separated and implemented by professional personnel respectively, so that all types of personnel can expand their respective lengths in the project.

All in all, it is to separate the interface from the logic.

 

Refer to C # code:

Using System; using System. collections. generic; using System. linq; using System. text; using System. windows; using System. windows. controls; using System. windows. data; using System. windows. documents; using System. windows. input; using System. windows. media; using System. windows. media. imaging; using System. windows. navigation; using System. windows. shapes; namespace Practice {// <summary> // MainWindow. interaction logic of xaml // /April 11, 2016 BY edian // </summary> public partial class MainWindow: Window {public MainWindow () {InitializeComponent ();} private void ListView_Loaded (object sender, RoutedEventArgs e) // implement dynamic completion for the gridview during listview loading {GridView gridview = new GridView (); gridview. columns. add (new GridViewColumn {Header = "ID", DisplayMemberBinding = new Binding ("Id")}); gridview. columns. add (new GridViewColumn {Header = "NAME", DisplayMemberBinding = new Binding ("Name")}); gridview. columns. add (new GridViewColumn {Header = "CATEGORY", DisplayMemberBinding = new Binding ("Category")}); listView1.View = gridview;} private void Button_Click (object sender, RoutedEventArgs e) // complete the Add function {string text1 = textBox1.Text; string text2 = textBox2.Text; string text3 = comoboBox1.Text. toString (); Boolean flag = false; // Flag. flag = false indicates that IDs are not repeated, if (text1 = "" | text2 = "" | text2 = "" | text3 = "") MessageBox. show ("Incomplete information", "Tips"); // the error message is Incomplete. else {foreach (Book item in listView1.Items) // cyclically judges the item. id (Book instance) is equal to a text1 in listView1.Items {if (text1 = item. id) {MessageBox. show ("Already have same ID number", "Tips"); // a reminder that the same ID Already exists. flag = true; // modify flag }}if (! Flag) // equivalent to if (flag = false) listView1.Items. add (new Book (text1, text2, text3);} private void Button_Click_1 (object sender, RoutedEventArgs e) // complete the delete function {if (listView1.SelectedItem = null) // determine whether a row in ListView is selected. show ("Nothing have been choosed", "Tips"); else listView1.Items. remove (listView1.SelectedItem); // Delete the selected row} class Book {public Book (string ID, string NAME, string CATEGORY) // constructor {Id = ID; name = NAME; Category = CATEGORY;} private string id; // encapsulation requirements // you can use {right-click ---> refactoring ---> encapsulate field} to automatically complete the get set function // The same public string Id below // you only need call Id to {get {return id ;} set {id = value ;}} private string name; public string Name {get {return name ;}set {name = value ;}} private string category; public string Category {get {return category;} set {category = value ;}}}}

Refer to the XAML code:

<Window x: Class = "Practice. mainWindow "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "Title =" MainWindow "Height =" 350 "Width =" 525 "> <Grid Margin =, 40,240 "> <TextBox x: Name =" textBox1 "HorizontalAlignment =" Left "Height =" 23 "Margin =, 120 "TextWrapping =" Wrap "VerticalAlignment =" Top "Width =" "/> <TextBox x: name = "textBox2" HorizontalAlignment = "Left" Height = "23" Margin = "192,240, 120 "TextWrapping =" Wrap "VerticalAlignment =" Top "Width =" 119,276 "/> <TextBox HorizontalAlignment =" Left "Height =" 0 "Margin =, 0, 0 "TextWrapping =" Wrap "Text =" TextBox "VerticalAlignment =" Top "Width =" 4 "/> <ComboBox x: name = "comoboBox1" Maid = "Left" Margin = "352,240, 120 "VerticalAlignment =" Top "Width =" 100 "> <ComboBoxItem Content =" culture "Height =" 23 "Width =" "/> <ComboBoxItem Content =" technology "Height = "23" Width = "100"/> <ComboBoxItem Content = "software" Height = "23" Width = "100"/> </ComboBox> <Button Content = "Add "HorizontalAlignment =" Left "Margin =" 134,276, 283,276 "VerticalAlignment =" Top "Width =" 75 "Click =" Button_Click "/> <Button Content =" Delete "HorizontalAlignment =" Left "Margin =, 43,139 "verticalignment =" Top "Width =" 75 "Click =" Button_Click_1 "/> <Grid Margin =", "> <ListView x: name = "listView1" HorizontalAlignment = "Left" Height = "170" verticalignment = "Top" Width = "432" Loaded = "ListView_Loaded"> <ListView. view> <GridView/> </ListView. view> </ListView> </Grid> <Label Content = "ID" HorizontalAlignment = "Left" Margin = "40,210, 0, 0 "VerticalAlignment =" Top "/> <Label Content =" Name "HorizontalAlignment =" Left "Margin =" 192,210, 0, 0 "VerticalAlignment =" Top "/> <Label Content =" Category "HorizontalAlignment =" Left "Margin =" 352,210, 0, 0 "VerticalAlignment =" Top "/> </Grid> </Window>

Corresponding interface:

Running interface:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.