I think the easiest way to explain this is by example.
I have a Datagrid with a data context of a list of People Objects:
People{
string Name;
int AstroSignCode;
}
I am using a code to store the astro sign because the values will be persisted in a database. I cant just use the astrology Object.
Then I have a Text Column which binds to this object and uses a converter which returns an AstrologySign Object from a static list of signs based on a cross reference between AstrologySign.ID and People.AstroSignCode:
AstrologySign{
string Name;
DateTime StartDate;
DateTime EndDate;
int ID;
}
So my converter is returning an Object instead of something displayable.
How do I bind the Column to the Member of the object returned from the converter?
my Xaml so far for the column is this:
I think that I might need to use a DataGridTemplateColumn but I’m not sure anymore.
I answered my own question. it took some time to figure this out because to me, it was not obvious.
I did infact need to use a DataGridTemplateColumn instead of a DataGridTextColumn.
What is happening here is the data context of the DataGrid is a list of People. Each Person has an astrosigncode which is an integer. This gets mapped by the AstrologySignConverter to an AstrologySign object which Contains the name. so I make a datatemplate and use the TextBlock control and i set it’s context to a binding using the converter then i bind to the element of the object that the converter returns.
It’s simple once you see that you can do it. Thanks anybody who tried to solve this!