다음을 통해 공유


Silverlight 2 Map / DataGrid Demo (Part 2)

In Part 1 we created a n-tier Silverlight application which used LINQ and Silverlight 2 including the new controls.  That version takes a simple text box parameter for the state we want to look for.  Now let's spruce it up a bit with a map component.  The end result will look like this:

image

I've posted the source code for the full demo here.  Hopefully you were able to create Part 1 without it.  But you'll need the map markup to do the next step.

Once you have downloaded the code, copy the map in page.xaml into your project.  After you reload the designer you'll see the USA map in the split pane view:

image

The xaml for the map is a Canvas and a large collection of <Path> items for each state.  A Path is a set of points that bound a region.  If you open page.xaml now in Expression you will be able to click on each Path item to see its name and location:

image

In this case I've selected Washington state which has the name Path_412.  Because the Path has a x:Name, we can write code against it just our button.  Navigate back to VS2008 and add the following code to the project:

image

Now when the user clicks anywhere inside the Path for Washington, our handler will get called allowing us to search for items in the database.

With a little more code we can also hook up hover effects to change the color as you move in/out of the state region:

image

As the mouse enters the Path for the state, its color is changed and vice versa.  Now that you have the basic mechanisms, you could start hooking up all sorts of behavior.  For example you could show the text name of the state, show the state flag, or even play a video bounded by the region.  These are the sorts of features that really set apart Silverlight from normal HTML/AJAX applications.

The obvious next step in the demo is to create a table of the state and path objects and hook up the events in a more generic way.  I've left this as an exercise to the user.

Hopefully these two tutorials have been useful for you, enjoy!

Comments

  • Anonymous
    April 06, 2008
    PingBack from http://mdavey.wordpress.com/2008/04/06/silverlight-reading/

  • Anonymous
    April 10, 2008
    The comment has been removed

  • Anonymous
    April 10, 2008
    The comment has been removed

  • Anonymous
    April 10, 2008
    The comment has been removed

  • Anonymous
    April 11, 2008
    Вот здесь можно посмотреть предыдущий пост из серии списка постов. Также некоторые ссылки на мои популярные

  • Anonymous
    April 11, 2008
    【原文地址】 April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight 【原文发表日期】 Friday

  • Anonymous
    April 11, 2008
    11 april Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, VISUAL STUDIO, Silverlight ASP.NET Meer ASP.NET Beveiliging

  • Anonymous
    April 15, 2008
    Voici l&#8217;article le plus r&#233;cent dans ma s&#233;rie Listes de liens .&#160; Visitez aussi ma

  • Anonymous
    April 17, 2008
    ASP.NET: آموزش های امنیت بیشتر در ASP.NET : سه آموزش آخر و عالی اسکات میشل در مورد امنیت ASP.NET سه آموزش

  • Anonymous
    April 17, 2008
    ASP.NET: آموزش های امنیت بیشتر در ASP.NET : سه آموزش آخر و عالی اسکات میشل در مورد امنیت ASP.NET سه آموزش

  • Anonymous
    June 15, 2008
    The comment has been removed

  • Anonymous
    July 21, 2008
    (以下内容全部整理自博客堂Scottgu博客中文版)Silverlight技巧,诀窍,教程和链接 【原文地址】SilverlightTips,Tricks,...