I have the below code-behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Yes, you'll need to set the DataContext somehow. It doesn't have a DataContext, because the Window doesn't have a DataContext unless it is set. The ListBox will get the DataContext if you do this in the constructor.
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}
Otherwise you can use RelativeSource, ElementName etc. in the Binding but I guess you knew that =)