I have a result set that has an Amount property and a Currency object w/ a Culture property.i.e.myItem.Amount (decimal)myItem.Currency.Culture (contains the value en-US, or de-DE as a string)
Each record's amount can be of a different culture.I already have a converter working via xaml that performs an (Amount * -1) and then uses a string.format w/ a format of C2 and the given culture so the proper currency format shows, just not getting the proper CultureInfo passed in; how do I get the myItem.Currency.Culture string property to the converter as the CultureInfo parameter. (If I have to change the Culture property to a CultureInfo object I will)Can someone please provide an example of how I might do this?
This is what I currently have working:xmlns:Converters="clr-namespace:AppName.Converters"
<igDP:Field Name="Amount"><igDP:Field.Settings><igDP:FieldSettings AllowEdit="False" EditAsType="{x:Type sys:String}"/></igDP:Field.Settings><igDP:Field.Converter><Converters:NegateAmount/></igDP:Field.Converter></igDP:Field>
TIA!Jason
There really isn't a way to do this. The Field is a single object that has no context of a single record. Whether it was a Framework(Content)Element (i.e. whether it had access to the DataContext) is really not relevant here. What you are looking for here would likely have to come as a feature request - perhaps some sort of selector to allow you to choose a parameter based on a given record. In the interim I think you will need to create an UnboundField and set the Value of the cell for that field based on the value of the Amount cell (e.g. in InitializeRecord/CellUpdated). Another approach would be to surface another property from your item class that has the negated value (or whatever the converter was going to do).
Here's the error I receive in the output window for the binding error. I just read somewhere binding errors are only shown in the output window. (love being new to WPF :) )
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Currency.Culture; DataItem=null; target element is 'Field' (HashCode=9884906); target property is 'ConverterCulture' (type 'CultureInfo')
This lead me to:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/aff23943-5483-40b2-816b-4ce687bc6bf8/
Which lead me to:http://wpfdisciples.wordpress.com/2008/10/09/frameworkelement-vs-frameworkcontentelement/
Please forward this information to the development team as it might help solve this issue after a possible hotfix. At this time I'm just going to manually perform the actions of the converter prior to binding and remove the converter.
Thanks for your replies!
Hello,
If you write that statement not in one line, but like this ? Will this help you?
<Setter Property="Foreground"> <Setter.Value> <Binding ConverterParameter="" Converter="" ConverterCulture="" /> </Setter.Value> </Setter>
Or you can see the names of the different options. I believe you are looking for ConverterParameter or ConverterCulture
Hope this helps,
Alex.
Thanks for the reply!
I believe my problem is figuring out the binding. If I could see an example of how to pass a property of the current row as the ConverterParameter my issue would be fixed.The data source is a List<MyItem> collection.and the properties I'm using are:myItem.Amount as the field valuemyItem.Currency.Culture as the string value for the culture, (en-US or de-DE as an example)<igDP:XamDataGrid.Resources><Converters:NegateAmount x:Key="NegateConverter"/></igDP:XamDataGrid.Resources><igDP:Field Name="Amount" Converter="{StaticResource NegateConverter}"ConverterParameter="{Binding Currency.Culture ****Where I need help*****}"><igDP:Field.Settings><igDP:FieldSettings AllowEdit="False" EditAsType="{x:Type sys:String}"/></igDP:Field.Settings></igDP:Field>
Thanks!
Hello Jason,
In the converter, I am assuming that you return the string like this:
return String.Format(....);
There is an overload of String.Format method, where you can pass IFormatProvider as a parameter?
Have you tried using it?