Ian Blackburn

April 2008 Entries

Virtual Earth JavaScript Intellisense for version 6.1 and for Google Maps

We have just released an updated version of the VE JavaScript Intellisense Helper which supports version 6.1 of VE.

I also received a mail from Roger Chapman who has completed a similar project for Google Maps

Oh and for those of us in the UK who were shocked to see VE replaced by Multimap for a few days, you will be glad to know this has now been reverted!

Cheers

Ian

 

del.icio.us Tags: ,
Technorati Tags: ,

Silverlight ObservableCollections from WCF and Linq to Sql

I have a ListBox in a Silverlight 2.0 app that is bound to some data coming from a WCF service that is returned from Linq to Sql.  The service is simplicity itself:

 

public List<CourseSection> GetCourseSections()
{
    CoursesDataContext db = new CoursesDataContext();
    return db.CourseSections.ToList();
}

 

Note: you have to mark your DataContext Serialization Mode as Unidirectional for the above to work (as shown)

image

 

I added a Service Reference to this from Silverlight and bound the data to a ListBox:

private void Button_Click(object sender, RoutedEventArgs e)
{
    CoursesService.CourseServiceClient client = new CourseBuilder.CoursesService.CourseServiceClient();
    client.GetCourseSectionsCompleted += 
          new EventHandler<CourseBuilder.CoursesService.GetCourseSectionsCompletedEventArgs>(client_GetCourseSectionsCompleted); client.GetCourseSectionsAsync(); TextBlock1.Text = "loading..."; } void client_GetCourseSectionsCompleted(object sender, CourseBuilder.CoursesService.GetCourseSectionsCompletedEventArgs e) { TextBlock1.Text = "loaded " + e.Result.Count(); ListBox1.ItemsSource = e.Result; }

 

Further into the code I wanted to be able to add and remove items from the ItemsSource and have the ListBox reflect that automatically.  As in WPF, this will not happen unless your ItemSource is bound to an ObservableCollection or a type that implements INotifyCollectionChanged and INotifyPropertyChanged.  So I needed to make that change, but how?

Turns out that you can do this easily when you create the service reference from Silverlight, by clicking the Advanced button in the service reference dialog.  This will show you the following where you can map the collection and dictionary types to the types in the drop down list.  Once you have selected ObservableCollection here, then changes to the ListBox ItemSource data will notify the ListBox automatically, and so show the changes to the data, without any further work from you.

image

Cheers

Ian

Missing WFC Service Configuration Editor?

wcf editorWhen you create a WCF Service in  VS 2008, it writes the service config into web.config.

Usually you can right click on web.config in Solution Explorer and select Edit WCF Configuration.

However I have noticed that the context menu item does not always show up. 

The answer: Select Tools > Wcf Service Configuration Editor instead; this will bring up the editor with nothing loaded, so you will then need to open the relevant config file.  However, just starting the editor seems to be enough to remind Visual Studio about that context menu item, so just exit the editor and go back and right  click on web.config - the Edit WCF configuration option has returned... ;-)

Cheers

Ian

Technorati Tags:

Windows Live IM Control - easy "Live Chat" on your web site

imageThe Windows Live IM control is a very easy way to add a "live chat" feature to your web site.

You can either use the server control that is in the Windows Live Tools for Visual Studio, or you can host the control with some html you can generate automatically

Whichever way you create the control, you "hardwire" it to a particular Live ID who then receives the incoming messages (via Live Messenger) - this user also needs to accept that their current status will be shown on the web site.

While testing make sure you don't login to the full IM and the Web control with the same account at the same time - or you'll be told that you "cannot start a conversation with yourself" - though some may disagree

Cheers

Ian

Technorati Tags: ,