I know I can apply FormatString to format Column Display in XAML. But I want to format Columns dynamically (depending on some conditions). How can I implement it in Code Behind? Thanks.
You can use valueConverter
It would look like
public class DecimalEditorValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return String.Format(culture, "{0:N2}", value); }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; } }
and in xaml use it with your control as
ValueConverter="{StaticResource DecimalEditorValueConverter }"
Hi, xamluser,
Thanks for your suggestion. If I understand it correctly, I can apply ValueConverter to format different columns at same time. However, my issue is that I need to format the SAME column dynamically. How to implement it? Thanks.
Hi,
((TextColumn)grid.Columns["YourTextColKey"]).FormatString = ....
-SteveZ
Hi, Steve,
There are two buttons that control the Display Mode.
You are right. I want to format the entire column. "...So if you're trying to do it on the entire column level, then you can just change that property. ..." How can I change the property in code behind? Thanks.
So what causes the condition to change?
The FormatString property on a TextColumn is for the entire column not a particular cell. So if you're trying to do it on the entire column level, then you can just change that property.
The data provided by SQL Server via RIA are decimal. I want the SAME column of grid to display only the integer part OR with three decimal places at different time, depending on the condition. If the FormatString can be implemented at code behind, we can set the FormatString conditionally.
Thanks.
Assuming your data implements INotifyCollectionChanged, then if you raise the PropertyChanged event when your data should update, the ValueConverter will automatically invalidate and be raised again, so you can then apply your "new" change to how the data is displayed.
Could you describe your scenario with a bit more detail, so i can give you a better suggestion on what to do.