Got another tough issue that we're seeing in our Silverlight app.
Our xamwebgrid is bound to an observable collection data source, with multiple template columns for display. The itemtemplate and edittemplates are used, text blocks for item and text boxes for edit.
One of the features of our app is to show money values in different currencies. So we have logic to switch the currency to Euros from US$, and vice-versa. The conversion is done when the user switches, and then we update the values. A converter takes care of capturing the correct culture and a standard ToString("C0") makes the values show with the correct currency symbol.
Except in random cases. We've determined this is not a code issue on our part, it is basically a paint bug with the grid. What we see is that, somewhat randomly, the currency symbol does not change, and only on randomly selected rows. More importantly, if I scroll the offending records out of view, and scroll back, the symbol will display correctly! This is why I call it a paint bug.
What I was hoping to find was a method to call to force a refresh of the grid to ensure things are updated, but the closest I could find was UpdateLayout, which has no effect at all.
Any ideas?
Hi,
Well, calling InvalidateData() should do the trick. However, i'd like to try to narrow down why the grid isn't invalidating.
Do you have a sample that you could attach that reproduces the problem?
Thanks,
-SteveZ
That may be possible but it won't come easy, as this is on a complicated screen in an app that I can't share.
I'll try the invalidate to see if that gives me a fix, and then I'll try to put together a sample repro page. Thanks for the tip, wouldn't have known to try that one (sounds scary! <g> )
-Chuck
Through bindings, i can't think of a good suggestion off the top of my head.
One option would be to add a CultureSpecific price property and then raise the PropertyChanged event for that property whenever the CultureName or Price properties change.
Thanks SteveZ.
Is there any better way of per row converting other than the way I have described above?
Hi Kev,
If you don't specify a path on a binding, then OneWay/TwoWay bindings don't work and they become OneTime bindings.
Sorry to raise this old thread again but i have the same issue. I have narrowed it down to the fact that the binding i use in the itemtemplate of my template column does not have a property path specified.:
<TextBlock Text="{Binding Converter={StaticResource DecimalToCurrencyFormat}, ConverterParameter='PriceC'}" />
The converter then gets the whole entity passed in as the value parameter. The converter then gets the required culture name from another property on the entoty so it can format the priceC to the correct currency.
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var ild = value as ItemLocationDetail;
if (ild.LocationCultureName != null)
var propValue = ild.GetType().GetProperty(parameter.ToString()).GetValue(ild, null);
CultureInfo ci = new CultureInfo(ild.LocationCultureName);
return string.Format(ci, "{0:c}", propValue);
}
var propValueDefault = ild.GetType().GetProperty(parameter.ToString()).GetValue(ild, null);
return propValueDefault;
If i use the following binding then it invalidates the cells fine when changes are made in code to the priceC and I see my updated prices in the UI.
<TextBlock Text="{Binding Path=PriceC, StringFormat=\{0:c\}}" />
But this binding does not allow me to alter the currency symbol per row so it's no use to me.
Your InvalidateData() suggestion does work but should I have to do this?
Thanks
Kev
Hey Chuck,
That'd be great.
And InvalidateData() isn't as scary as it sounds. :) Basically what it does, is make sure that all data operations for the xamWebGrid are up to date, such as sorting, filtering and groupby. However, in the process it makes sure to invalidate the cells that are currently in view, thus it should solve your problem.