1

I am trying to display my List in a ListView using a GridView. I am using dynamic binding as my list view changes. it's gridview for other purposes.

I have already used similar code twice and had no issues. I have checked every variable using a debugger and executed the code step by step and everything seemed normal.

// the code of the function
public void loadPairsIntoListView(object sender, RunWorkerCompletedEventArgs args)
        {
            XmlComparator xComp = XmlComparator.getInstance();
            List<ComparePair> listOfPairs = xComp.getListOfPairs();
            multiCompareListOfCompared.ItemsSource = listOfPairs;
            multiCompareModelLabel.Content = listOfPairs[0].model.trueName + " " + listOfPairs[0].model.envName.ToUpper();
            GridView myGridView = new GridView();
            myGridView.ColumnHeaderToolTip = "Objet recap";
            GridViewColumn gvc1 = new GridViewColumn();
            gvc1.DisplayMemberBinding = new Binding("compared.trueName");
            gvc1.Header = "nom";
            gvc1.Width = 100;
            myGridView.Columns.Add(gvc1);
            GridViewColumn gvc2 = new GridViewColumn();
            gvc2.DisplayMemberBinding = new Binding("compared.envName");
            gvc2.Header = "environnement";
            gvc2.Width = 100;
            myGridView.Columns.Add(gvc2);
            GridViewColumn gvc3 = new GridViewColumn();
            gvc3.DisplayMemberBinding = new Binding("anomalies.Count");
            gvc3.Header = "Ecarts";
            gvc3.Width = 100;
            myGridView.Columns.Add(gvc3);
            multiCompareListOfCompared.View = myGridView;
            Log.S();
        }

// the class i'm trying to bind

public class ComparePair
    {
        public XmlFile model;
        public XmlFile compared;
        public List<int> anomalies;
        private const int diffOnlyMarge = 10;

        /// Methods ...
}
// 

I am getting an output where the List is actually binded to the ListView (i can click on and use every row) but the rows are actually empty. I am getting all the three columns with their names but their rows has no "visual content" while still has the object bind to it.

What i am expecting is to see the actual values i have bind to each column.

I hope i have been clear enough. Tell me if you need more precision.

Haroon nasir
  • 648
  • 1
  • 7
  • 21
  • 3
    `public XmlFile model;` is a field. It needs to be a property for bindings to work: `public XmlFile model { get; set; }`. Same for the rest. – 15ee8f99-57ff-4f92-890c-b56153 Apr 23 '19 at 14:08
  • Like Ed says, for data binding to function, you need to bind to Properties. And if you want the UI to update when the data changes, you need to implement INotifyPropertyChanged https://stackoverflow.com/questions/1315621/implementing-inotifypropertychanged-does-a-better-way-exist – Stewbob Apr 23 '19 at 22:25

0 Answers0