Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Silverlight Currency (Databinding)
6 replies. Latest Post by nosuchthingas2 on October 17, 2008.
(0)
andyboyne
Member
105 points
56 Posts
08-29-2008 10:43 AM |
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.cam...
Participant
1918 points
332 Posts
08-29-2008 10:57 AM |
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.
08-29-2008 11:15 AM |
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.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
09-01-2008 3:00 AM |
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.
09-01-2008 6:22 AM |
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,
09-01-2008 7:07 AM |
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.
nosuchth...
53 points
51 Posts
10-17-2008 10:35 AM |
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!