Programmatically binding List to ListBox

后端 未结 4 546
说谎
说谎 2020-12-09 09:25

Let\'s say, for instance, I have the following extremely simple window:



        
4条回答
  •  一整个雨季
    2020-12-09 09:48

    Use Binding class if you want to customize binding:

    List listOfNames = new List() {"a", "b"};
    Binding myBinding = new Binding();
    //set binding parameters if necessary
    myBinding.Source = listOfNames;
    eventList.SetBinding(ItemsControl.ItemsSourceProperty, myBinding);
    

    or

    directly assign data to ItemsSource property:

    eventList.ItemsSource = listOfNames;
    

提交回复
热议问题