November 23rd, 2009, 01:20 PM
Canít seem to set the DataContext in XAML
Iím experimenting with data binding. I wrote a simple test program with only one object representing a person and two TextBoxes bound to its properties (first and last names), which reside in the StackPanel layout. In the beginning, I was assigning the DataContext in the windowís constructor:
base.DataContext = m_objPerson;
Then Iíve tried a different approach. Instead of assigning DataContext in code, I would like to assign it in XAML. StackPanel layout has a DataContext property. Shouldnít it set the DataContext properties for all of the components contained in the layout? Iíve removed the assignment from code and added an assignment in XAML:
Unfortunately, the text boxes were no longer bound. Could anyone help me find the error?
Tags for this Thread
Click Here to Expand Forum to Full Width