Question: Objectives: 1 . Use a collection initializer to populate the collection. 2 . Maintain objects in a collection. 3 . Search a collection to find
Objectives:
Use a collection initializer to populate the collection.
Maintain objects in a collection.
Search a collection to find matching data.
Preamble:
Maintain a collection of Items for sale in a Dictionary collection. Locate data in the collection based on an ID and display
the item information. The Main Page UI and Item class are provided. You must complete the application by writing code
behind the page.
Instructions:
Open the starting project files provided. Review the Main Page XAML and the Item class. Build and run the project
before you begin. On the left side of the UI the user enters items to store in the collection. On the right side the user
enters ID numbers to locate an item and display the item information.
Review the Main Page code. Notice two events are registered. The Submit click event fires when the user wishes to
add a new Item. The ID key down event fires when key input is entered. The event checks for the enter key pressed
and attempts to locate an item in the collection.
Declare a Dictionary for storing Item objects. The key for each item is an integer id
In the Submit click event write code to obtain the users input and add a new Item object to the collection. The Item
ID property returns the items unique id Notice the Item class throws exceptions. Add exception handling and display
an appropriate message for invalid input.
In the ID key down event write code within the if statement provided to locate a matching item based on the users
input. Check the users input. If the input is invalid display an appropriate message. If the id does not exist display an
appropriate message. If the id matches an item in the collection display the items ToString information in the textbox
named txtOutput.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
