Skip to main content

Microsoft Silverlight

Answered Question Use a Linq Query in Value ConverterRSS Feed

(0)

Congero8
Congero8

Member

Member

7 points

18 Posts

Use a Linq Query in Value Converter

 I am trying to create a value converter that will convert an integer value in a ADO.Net Data Services Data Source to a text value that will be displayed in a Silverlight data grid. I'm able to retreive the correct value with my dataservices query but I don't know how to return the value to the grid.  I am actually able to retreive the correct value in the Function LoadTransactionTypeCallback.  How can I send this value back to the grid in my convert function?

Thanks 

 

 

Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert

Dim q = (From p In svc.TransactionType _

Where p.TransactionTypeID.Equals(value) _

Select p)

Dim TransTypeQuery = CType(q, DataServiceQuery(Of TransactionType))

TransTypeQuery.BeginExecute(AddressOf LoadTransactionTypeCallback, TransTypeQuery)

End Function

Private Function LoadTransactionTypeCallback(ByVal Result As IAsyncResult)

Dim TransTypeQuery = _

CType(Result.AsyncState, DataServiceQuery(Of TransactionType))

Dim TType = TransTypeQuery.EndExecute(Result).ToList

For Each T In TType

Return T.Description.ToString   ' This is the value I want to return to my grid

Next

End Function

anyeone
anyeone

Participant

Participant

811 points

182 Posts

Answered Question

Re: Use a Linq Query in Value Converter

I haven't tried this but I suspect you will have a problem given the asynchronous nature of the service call and the synchronous nature of the IValueConverter.Convert method.

You may be better off not using the ValueConverter here and instead having your ADO.NET Services call retrieve both your integer value and the corresponding description at the same time, and use these to populate an object which can be set as a DataContext for your grid.  Then you can use normal OneWay binding to a TextBlock or other control inside your grid, binding to the "Description" property on the object you defined.

Alternatively if you have only a fixed number of Transaction types, you may want to load the list of int/Description value pairs into a static resource as part of your initialization and use that as the source for a ValueConverter. I haven't done this myself, it is just an idea.

But, I suspect you will have problems trying to run a service call from inside a ValueConverter.

--
Anye Mercy
AnyeDotNet.blogspot.com

Please "Mark as Answer" the posts that help you - this lets others know the problem has been solved and helps others having the same problem know which solution works. Thanks!
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities