Hello,
I am trying to "internationalize" an existing project that uses igDP:XamDataGrid.
The grid is data bound to a class, and The header row int he grid shows the field names, as defined in the class.
The header thus look like English. I would like to display translated strings on the header, taken from a resource file.
What is the best way to do that?
Being an older project, I am required to use VS2008, and being a newbie to XAML I am fish out of water.
Thanks for your help.
Hello Ajit,
Thank you for the detailed description of the functionality you are looking for.
In order to set a custom string as a header of the Field in the XamDataGrid, you can set the Label property of the Field.By default if the Label property is not set, the Field will display the name of the underlying property as a header. If the Label property is set, it will take precedence over the name of the underlying property.
Code-behind:
public class Item{ public string Make { get; set; }}
XAML:
<igDP:TextField Name="Make" Label="Localized Make" />
If you have any questions, please let me know.
Tacho,
Thanks for the answer. I think I have a problem though. I am not defining the fields in xaml. The fields are auto populated when I databind the grid to a collection of objects. The labels in that case are same as the field name of the objects (type, rather) in the collection.
Apparently the fileds are populated using the attribute called "DisplayNameAttribute", of each of the fileds of the object in the collection. I found in internet a way set the attribute value such that it returns localized string. I had to creat a derived class from "DisplayNameAttribute" and make it return the localized string. this seem to be working.
Your answer seem to be much simpler than, if I can set the label value of each field without changing the current structure that I have, namely databinding from the object collection rather than specifying on xaml. Is there a way to achieve that?
thanks in advance.
Thank you for the feedback.
When the Fields are autogenerated, in order to set their Labels I can suggest you handle the FieldLayoutInitialized event. This way we can be sure that the layout is successfully initialized and we can alter the Fields accordingly. In addition, we can always set the Labels in another event or moment (if we are sure that the respective layout has already been initialized).
private void dataGrid_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e){ var fieldLayout = e.FieldLayout; foreach (Field field in fieldLayout.Fields) { field.Label = "[Localized] " + field.Label; }}
Using the code from above should not have any impact on the structure of your application.I have attached a sample application that demonstrates this approach.
Thanks! It works, and it is much simpler than the solution that I had earlier.
Thank you for your feedback.
I am glad to know that I was able to help you achieve the functionality you were looking for. I believe this thread can help other people looking for a similar solution.