WPF series learning --- ListBox

Source: Internet
Author: User

Recently, I was not very busy. I came to learn something. I saw a lot of friends on the Internet studying WPF, and I also came to give myself a chance,

Put your ownArticleWrite it down, hoping to help 0.1% beginners, so I will not be able to write it in white, and my ability to express myself is limited.

I don't want to talk too much about text. I generally like simple text, but it's okay to be clear and clear.

1. Introduction to The ListBox control

ListBox: It is basically the same as in winform. Here, it has many more attributes;

Ii. View running results

 

ProgramInitial page of Running

Click ">" to add the item to the listbox2 page.

Add a value to listbox1

III,Code

1) Add a value to ListBox when the form is loaded

Private VoidWindow_loaded (ObjectSender, routedeventargs E)
{
Listbox1.items. Add ("2. U.");
Listbox1.items. Add ("2. U. U.");
Listbox1.items. Add ("2. ü úzomä¶ × ó ×ó");
}

 
2) Add the value of listbox1 to listbox2
 Private VoidButton#click (ObjectSender, routedeventargs e ){Try{Listbox2.items. Add (listbox1.selecteditem. tostring (); listbox1.items. Remove (listbox1.selecteditem. tostring ());}Catch(Exception ex) {MessageBox. Show (ex. tostring ());}}
 
3) dynamically add values to listbox1
 
Private VoidBntadd_click (ObjectSender, routedeventargs e) {listbox1.items. Add (textbox1.text. tostring (); textbox1.text =String. Empty ;}
 
4) Add the value of listbox2 to listbox1
Private VoidButton2_click (ObjectSender, routedeventargs e ){Try{Listbox1.items. Add (listbox2.selecteditem. tostring (); listbox2.items. Remove (listbox2.selecteditem. tostring ());}Catch(Exception ex) {MessageBox. Show (ex. Message. tostring ());}}

 

 

The above is a simple example, which is as simple as I can't talk about it. I hope that a beginner will have an entry, and I will also have an entry.

I hope you will give me your valuable comments and correct me!

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.