c# - Access DataContext in code-behind -
Be careful, this is a basic question (I think).
I have a user control, which is MyUserControl. I use it for my ListBox in a datatapplet:
& lt; L: MyUserControl DataContext = "Test" /> Now I want to access this DataContext code in MyUserControl, and I hope DataContext must include a string object with "Test" content. However, the datacontext is zero. What am I missing here?
If you want to use DataContext property in the data behind the data, give the user control ( Or any control for that matter) Name:
Back code:
myControl.DataContext = someobject;
Although setting a data concave set for "test" in your example will not accomplish anything.
Read on data binding in WPF
Comments
Post a Comment