How can I bind an ItemsControl.ItemsSource with a property in XAML?

后端 未结 4 559
半阙折子戏
半阙折子戏 2021-01-17 14:03

I have a simple window :



        
4条回答
  •  无人共我
    2021-01-17 14:40

    That's because the data context of your view hasn't been set. You could either do this in the code behind:

    this.DataContext = this;
    

    Alternatively, you could set the Window's DataContext to itself - DataContext="{Binding RelativeSource={RelativeSource Self}}"

    You're much better off though investigating the MVVM design pattern, and using an MVVM framework.

提交回复
热议问题