With a listbox like this defined in your XAML:
[XAML]
<ListBox x:Name='myLB' ></ListBox>
You can do so in your code-behind as follows:
[C#]
public MyWindow()
{
InitializeComponent();
Binding binding = new Binding();
binding.Source = this;
PropertyPath path = new PropertyPath('ListSource');
binding.Path = path;
// Setup binding:
BindingOperations.SetBinding(this.myLB, ListBox.ItemsSourceProperty, binding);
}
public string[] ListSource
{
get { return new string[] { 'testing', 'test1' };}
}
Share with