I have data in my XamDataGrid where each element has two properties.
class Thing
{
public DateTime Occasion { get; set; }
public string Information { get; set; }
}
I'd like to show three columns, though. One for each of the properties and an additional one for the date but only showing the year. At the moment I do that by introducing an auxiliary class as follows.
class ThingUi
public String Year { get{ return Occasion.ToString("yyyy"); } }
I'd prefer to bind a two columns to the same field and simply format or convert it to my needs. At the moment, the stupid computer says that such an object doesn't exists in the collection provided (from my view model), as if the field has been "used up" at the first binding attempt. NB. I only need to display the date. Any manipulation and storing back to the database's done elsewhere.
Hello Konrad,
Thank you for posting.
I have been looking into your question and have created a small sample application for you.
In the sample application I have a simple XamDataGrid, bound to a collection of two properties. In the XAML I am manually creating the Field. There are two Fields for the properties of the collection.
The third Field in the XamDataGrid shows only the year from the second (Date) property. I have achieved this by binding the third field to the second one and using a converter I am getting only the year from the Date property.
Please find the attached sample application and feel free to let me know if you have any further questions on this matter.
It didn't work on my system, probably because we're using an old version of the software. However, I managed to resolve it in another way, which I'd like you to comment on. I used something called unbound field, instead of the usual field. In there, I could bind (although I had to explicitly specify the type and some other stuff).
My follow-up question is if you could confirm my approach. I fear that - although seemingly working - it's going to create a bunch of problems for me in the future.