I agree with the comment from @inxs. But to make this work move InitializeComponent()
after the creation of myBtCollection
public MainWindow()
{
myBtCollection = new ObservableCollection<Button>();
...
InitializeComponent();
}
or implement INotifyPropertyChanged for myBtCollection
.