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.
I have been looking into your latest post.
Since 14.2 version of our controls the UnboundFields are obsolete. What I can suggest is using a Field and setting it's BindingType property to UseAlternateBinding. The BindingType property is created to use the Field as an UnboundField. More about this you can find on the following link from our documentation: http://help.infragistics.com/Help/Doc/WPF/2015.2/CLR4.0/html/xamDataPresenter_Add_Unbound_Fields_to_a_DataPresenter_Control.html
The bellow code snippet is an example of how the Field can be used as an unbound one. Also, this is the code I have used to bind an additional Field to the same property in the sample application I have attached in my previous post:
<igDP:Field BindingType="UseAlternateBinding"
Label="Year Only Field"
AlternateBinding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.Date}"
Converter="{StaticResource YearConverter}">
</igDP:Field>
In the converter I am executing the following code to get and display the year from the Date property:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
if (value != null)
DateTime date = (DateTime)value;
string year = date.Year.ToString();
return year;
return value;
Please do not hesitate to let me know if you have any further questions on this matter.