Skip to main content

Microsoft Silverlight

Answered Question Silverlight Currency (Databinding)RSS Feed

(0)

andyboyne
andyboyne

Member

Member

105 points

56 Posts

Silverlight Currency (Databinding)

How is currency (of the databinding kind) handled in Silverlight? 

I am looking for similar functionality to (Winforms CurrencyManager / WPF ICollectionView etc.).  I know there is ICollectionView in Silverlight but the only concrete implementor is internal, and the interface lives in System.Windows.Controls.Data - it seems bit extreme to pull in a 300kb assembly just for one interface.  I was hoping for similar behaviour to Wpf, where lists are automatically wrapped in a default ICollectionView - is there a similar mechanism Silverlight?

 Cheers,

 Andy

chad.campbell
chad.cam...

Participant

Participant

1918 points

332 Posts

Silverlight MVP

Re: Silverlight Currency (Databinding)

Hi Andy,

 If you want to display currency information, you will probably need to use an IValueConverter (http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(VS.95).aspx). You can use the Convert method to customize how your currency is presented when your data is being bound.

If this answers your question, please select "mark as answer", otherwise, please post a follow up question. Thanks!
Chad Campbell

Author of Silverlight 2.0 in Action Blog: http://cornucopia30.blogspot.com

andyboyne
andyboyne

Member

Member

105 points

56 Posts

Re: Silverlight Currency (Databinding)

I believe you have gotten the wrong end of the stick.  I am not talking about currency in the monetary sense, rather the 'which item is "current" in a list' sense. 

 Cheers,

 Andy

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Silverlight Currency (Databinding)

Unfortunately Silverlight doesn't have a list type that will tell you which item is currently selected. But if you're using a selectable Control, such as ListBox and DataGrid, you can simply reference the SelectedItem property of the Control. This property will point to an item in your data source.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

andyboyne
andyboyne

Member

Member

105 points

56 Posts

Re: Silverlight Currency (Databinding)

Ok, so what is the suggested alternative to creating an application with similar functionality to this:-

http://inpics.net/tutorials/access2003/forms16.html  (sorry about the poor link, it was one of the first hits that came up in a search!)

I.e. I have textboxes bound to lists - it is very common to have lists but not display them in ListBox etc.  Are we saying that this sort of interface is not possible in Silverlight? 

Many thanks,

Andy

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Re: Silverlight Currency (Databinding)

As a simple workaround, you create such a list manually. For example, use an ID property of type int to determine the id of the item in the list. When the user clicks the previous/next Button, you search for the item with the previous/next id in the list, and display it in the ContentControl.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

nosuchthingas2
nosuchth...

Member

Member

53 points

51 Posts

Re: Re: Silverlight Currency (Databinding)

This workaround makes sense, but I'm curious as to how the SL controls are able to perform currency operations but I can't.  I'm able to easily seutp a master-details databinding scenarios based on an ObservableCollection with a ListBox and a few TextBoxes.  It just works.  One thing I'd considered doing was to create a custom ICollectionView that would wrap any List (similar to what'd one in the DataGrid internals) and provide currency.  If I took that step would all list controls obey the currency of the ICollectionView?  I know this works for a DataGrid but would it also apply to ListBox and ComboBox?

 EDIT: Apparently I'm wrong!  It doesn't look like I can acheive master-details databinding in SL without manually setting the DataContext for my details controls when the selection changes in the master element.  I'm hoping implementing an ICollectionView will fix this (at least as long as I use a DataGrid for the master list).

 Thanks!

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities