Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to set Window.DataContext declaratively in XAML

$
0
0

Hi,

In my window, I declare and populate an ObservableCollection<Person> _persons;  Then I assign it as the DataContext of the window like this: this.DataContext = _persons;

I have a listbox in the window and in XAML I bind it to the collection like below which works well.  My question is how do I declaratively set the datacontext in XAML, instead of codebehind?  I've played around with <Window.DataContext/> but could get it right. 

<ListBox
                 ItemsSource="{Binding}"
                 DisplayMemberPath="FullName"></ListBox>

 


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>