Stock Screen (Silverlight For Windows Phone) Part 5

Stock Transaction Detail Page

1. Add a new page, right click on the project, select Add New Page and name it DetailStockAnalysisPage.xaml.

tmp1C-257

2. Modify the XAML code so that it looks like this:

tmp1C-258

 

 

 

tmp1C-259

3. Prepare a ViewModel to display the company transaction data of a company. Right click on project and select Add Class, name it SignalViewModel.cs. Type the code below:


tmp1C-260

 

 

tmp1C-261

4. For SignalModel main class, create a new class. Right click on project, select Add Class, and name it MainSignalViewModel.cs. Insert the following code:

tmp1C-262_thumb[2][2][2]

5. Open DetailStockAnalysisPage.xaml page and modify the code: Declare a variable to store parameters from the previous page

tmp1C-263_thumb[2][2][2]

When the application is navigated to the said page, it will call a web service. The parameters for the web service are retrieved by doing a string query on the previous page.

tmp1C-264_thumb[2][2][2]

 

tmp1C-265_thumb[2][2][2]

Then parse the fetched data using LINQ to XML.

tmp1C-266_thumb[2][2][2]

6. Open StockAnalysisPage.xaml page and add the code below in MainListBox_SelectionChanged event handler:

tmp1C-267_thumb[2][2][2]

7. Press F5 for results. You can select a company from the list and see the analysis for its stock.

tmp1C-268_thumb[2][2][2]

Adding Company List

An interesting feature in Windows Phone is the ability to do Push Notification using Microsoft service, Push Notification Server. Using this push, developers can send new data to an application without forcing the application to do constant polling to data provider. This means that without having to be active, application can still fetch the newest data.

This scenario fits perfectly for application like stock screen. Assume this application uses the service, then we will create a mechanism how users can select companies to subscribe, so that they will receive information actually from the selected companies.

1. Insert a page, right click on project, select Add Page -> Windows Phone Portrait Page and name it Subscription.xaml.

tmp1C-269

2. Add the following code so that the page layout will look like the figure below.

tmp1C-270

 

 

tmp1C-271

What you should notice from the code above is the declaration of two different data templates. The first data template is used to displayed the list of subscribed companies, along with a delete button to remove a company from the list. The second template is used to display available companies along with an add (+) button to add the company to our subscription list.

tmp1C-272

3. Add the resource icon that will be used, obtainable from C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Icons. Do this by right clicking on project, select Add Existing Item and find app.bar.delete.rest.png icon and app.bar.add.rest.png from the said folder.

tmp1C-273_thumb[2][2][2]

4. Open Subscription.xaml.cs. Add the following line of codes:

Declare a variable to contain the list of subscribed companies and non-subscribed companies.

tmp1C-274_thumb[2][2][2]

On Loaded() event handler add a function to fetch data from available services. Then parse the return value.

tmp1C-275

 

 

tmp1C-276

 

Use LINQ to XML.

tmp1C-277_thumb[2][2][2]

 

tmp1C-278_thumb[2][2][2]

5. Double click the Add button and add an event handler. When this button is pressed, the screen will display a list of companies the user has not subscribed to.

tmp1C-279

6. Now add a function to handle deletion/addition to the list. We add a handler to handle MainListBox_SelectionChanged event.

tmp1C-280

 

 

tmp1C-281

Note: The code above is not the only solution to handle deletion and addition of data. Let’s just say "it works" but it isn’t necessarily the best solution. At the very least it is enough for current purpose. You should consider not using a MessageBox in the real application.

7. Press F5 and see how the application works. Press the delete icon to remove a company from the list. To add a company, click Add and select one of the available company. We will feel the advantage of using MVVM schema and INotifyPropertyChanged, with which we can delete an item in an observable collection and the application’s interface will automatically updated to the latest condition.

tmp1C-282

 

 

tmp1C-283

Next post:

Previous post: