First Look at Using Expression Blend with Silverlight 2
page 12 of 14
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 52129/ 88

Implementing our Chat functionality

Now that our we've used Expression Blend to databind our control UI, and to tweak and polish the interactivity of the UI, let's go back to Visual Studio and write the code that implements the UI chat behavior functionality.

Specifically, we'll add the below code to our Page constructor to initiate a ChatSession with a remote user, and then handle the scenario where the "Send" button is clicked to send a message to the remote user.

Figure 53

When we add the above code and re-run the application we'll see that our UI now databinds to a ChatSession with "ScottGu" as the RemoteUserName (instead of the fake design-time data we defined earlier).  When we type text in the message TextBox and click the customized Send button our Listbox is automatically updated with the chat history:

Figure 54

Why did the ListBox automatically update you might wonder?  It did this because the ListBox was data-bound to the ChatSession.MessageHistory property - which is of type ObservableCollection<ChatMessage>.  This means the collection automatically raises change notifications when a new ChatMessage object is added to it, which the ListBox then detects and uses to update itself with the new data. 

No explicit code was required by us to have the ListBox reflect these changes.  The clean view/model binding architecture of our application automatically handled it for us.


View Entire Article

User Comments

Title: The code is not visible   
Name: Rui Montes
Date: 2008-12-21 2:26:06 PM
Comment:
Hi.
I have bem following this tutorial,But stoped her becouse I cant read the code.I






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 8:36:24 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search