In this blog let us discuss about how to add and remove items to the list view in a Windows phone application. While we click on add button a popup with text box and two buttons (OK, CANCEL) should be displayed. The text box items should be displayed in list view. When we click on remove button the selected item should be removed from the list.
- Open Visual studio and start new windows phone app project.
- Add controls like list view, buttons (Add, Remove), popup, text box to your design.
In the above image we can see the xaml code for the UI design of the particular controls. For a better UI the popup control is placed in a stack-panel and within a grid the controls like text box, buttons were placed.
So when we click on add button a popup should be raised with a textbox and two buttons(OK, Cancel). For this in the button click event of add we should write the below code
When we click on add button a popup with its controls will be displayed with the help of above code
After this when we write a particular text in textbox and click on OK the textbox item should be displayed in the list view. For this add the below code in Ok button click event in your popup control
So when we write something in textbox and click on OK the text will be displayed in the list view item.
The popup should be disappeared when we click on cancel button. For this, write the below code in the cancel button click event
To remove the selected item from the list view write the below code in the remove button click event.
The output is shown below. So while we click on OK the textbox item will be added in the listview. When we select particular item and click on remove then the item will be removed. When we click on cancel the popup disappears.