Search code examples
silverlightasp.net-4.0domainservicescomponentart

How to set guage value for component art control


I have a Guage control in MainPage.xaml which needs three value (value, minimum and maximum). I have written the logic to get these three values from database in a stored procedure.

Please let me know how can I call these value in DomainService and bind the guage control properties to it.


Solution

  • Below I will elucidate my knowledge dump as it took me some time to figure this out precisely, and I'd like to contribute this per SO's documentation guidelines for anyone other than us:

    0) I'm going to assume you have your stored procedures all implemented and are utilizing RIA services (as they're simpler for Silverlight development)

    1) In the .Web, add a new EDM - you'll need to pull in all stored procedures manually via import function. At this point the autogenerated code part should be done for you, go ahead and build your project.

    2) Time to add your domain service. Add a new Domain Service, this won't automatically generate code to pull in your stored procedures.

    3) Next, visit leeontech (http://leeontech.wordpress.com/2010/05/24/ria-services-and-storedprocedures/) for some manual coding based on your stored procedure definitions. What you're doing here is exposing data from stored procedures.

    4) Start using your newly created classes

    5) In silverlight, when you use Gauge on the front end side, make sure you assign max first using Math.Max() and similarly min using Math.Min() methods in the Load completed event handler. This way you are guaranteed that the asynchronous request is completed and you have values available. Actually in Visual Studio its pretty easy to debug that event handler even.

    ps: The visual studio tooling can recognize and allow you to create complex types based on your stored procedures you have implemented in step 1. As my personal best practice I like to assign the return column names as uniquely as I possibly can, thereby using them in client code the same way.

    In stored procedure's final select I'll do something like

    SELECT actualValueInDatabase as clientSideDataTypeIWant...

    if that makes sense

    If any of the above isn't clear, please let me know and I'll try to update with more information.

    Good luck!