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
805
Discrepancy in XamDataGrid binding when Explicit Interface is used
posted

Hi,
   

I have a scenario where I have to implement interface explicitly. I have simplified the case with the following code:

 

public interface IText

{

      string Text { get; set; }

}

 

public class MyText : IText

{

      public int Text { get; set; }

      string IText.Text{ get; set; }

 

      public MyText()

      {

            Text = 1;

            ((IText)this).Text = "Text";

      }                            

}

I have to bind list of IText  data in XamDataGrid:

List<IText> list = new List<IText>();

list.Add(new MyText());

list.Add(new MyText());

list.Add(new MyText());

xamDataGrid.DataSource = list;

I was expecting XamDataGrid would bind "Text" but it is showing "1" in the rows. Besides, I used similar case for a Console application with the following statements and it shows "Text" in the console.

foreach (var item in list)

{

      Console.WriteLine(item.Text);

}

Am I missing something or do I have to provide additional statements in order to have the data bind with string Text instead of int Text?

Regards,

Balaji Rajendran

CCH, WK - Torrance, CA

 

  • 69686
    posted

    Hello Balaji,

    The XamDataGrid creates Fields only for the public properties of the underlying class. I believe that your (string) Text property is private if you do not set an access modifier.