Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
How to bind two columns to the same field in the data source?
posted

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 DateTime Occasion { get; set; }

  public String Year { get{ return Occasion.ToString("yyyy"); } }

  public string Information { get; set; }

}

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.

Parents
  • 22015
    posted

    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.

    DataGrid_TwoFieldsSameProp.zip
Reply Children