Page view counter
Silverlight Currency (Databinding)
Last post 10-17-2008 10:35 AM by nosuchthingas2. 6 replies.
Sort Posts:
08-29-2008 10:43 AM
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

andyboyne

Loading...
Joined on 03-17-2008
Posts 30
08-29-2008 10:57 AM
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

chad.campbell

Loading...
Joined on 02-06-2007
Louisville, KY
Posts 323
08-29-2008 11:15 AM
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

andyboyne

Loading...
Joined on 03-17-2008
Posts 30
09-01-2008 3:00 AM
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.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,688
09-01-2008 6:22 AM
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

andyboyne

Loading...
Joined on 03-17-2008
Posts 30
09-01-2008 7:07 AM
Marked as Answer
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.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,688
10-17-2008 10:35 AM
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!

nosuchthingas2

Loading...
Joined on 03-31-2008
Washington, DC
Posts 21
Microsoft Communities