Saturday 5 November 2011

Release the Power of Silverlight Data Binding

DataBinding in Silverlight is so powerful, properly using it can make your work extremely easy and save you tons of time.

In this Live Demo I demonstrated how to use Data Binding to enable a tree view node to implement Add, Delete, or Edit action

You can also download the Source Code here , since I am still updating this application, so the source code would be different every few days.


I didn't use any weird third party controls such as Telerik, it's just Silverlight Toolkit controls and other Silverlight foundation knowledge 


If you really interested, you can download the source code as your real project's  template(it's quite easy to extend other functionalists by yourself), it's totally free. I am very happy if you like this project.



Let me briefly introduce what it use for.

Suppose you are a Manager of a big Property Management Inc, You want to edit building information(that means Add, Edit or Delete a building), and you want to continue editing the Floors in this building, and the rooms in some particular Floor

this small Silverlight application is to help you implementing your work. By hovering the mouse to Building, Commands for this building will appear, including Edit, Add Floor, or Delete, Same command will appear for Floor and Room

By clicking the Edit or Add commands, a child window will appear to let you input or modify some basic information(currently only Name, but I will add more fun stuff later)

the Process is easy and straightforward,in the back, it is supported by well organized data(we call it ViewModel), without these neatly wroted data, the UI's code behind would be in a big messy if to implement the same functionality.



How to use it, at first, when you click



a Child Window would pop up letting you input a building's basic information

















After that, a building item will be created and you can see it in the tree




when your mouse hover the Building, some other command icon would appear




this include an default "Edit" icon and an Expender, clicking the Expender you will see more commands




that would include a "Add Floor" command, "Delete Current Building" command, and a "Change Icon" Toggle Button. By Clicking the "Change Icon" toggle Button, a ListBox would appear letting you choose different icons











I changed the ListBox's ItemPanelTemplate to be a WrapPanel and make the Background to be transparency so that it looks more professional.

You can find similar fonction in Floor and Room items

everything listed above are done through DataBinding, now I briefly introduce how this application is designed and how these commands are bind to the VewModel

No comments:

Post a Comment