WPF Databinding

后端 未结 6 1652
夕颜
夕颜 2020-12-10 14:21

Can anyone point me to a good resource (or throw me a clue) to show me how to do DataBinding to controls (ComboBox, ListBox, etc.) in WPF? I\'m at a bit of a loss when all

6条回答
  •  独厮守ぢ
    2020-12-10 14:59

    in code behind -- set the DataContext of your list box equal to the collection you're binding to.

    private void OnInit(object sender, EventArgs e)
    {
      //myDataSet is some IEnumerable 
    
      // myListBox is a ListBox control.
      // Set the DataContext of the ListBox to myDataSet
      myListBox.DataContext = myDataSet;
    }
    

    In XAML, Listbox can declare which properties it binds to using the "Binding" syntax.

    
    

提交回复
热议问题