Need to edge out the competition for your dream job? Train for certifications today.
You can use any type as a data source as long as it has a public parameterless constructor and at least one public property. Here's a sample of binding to System.String. In the example below, both TextBlock elements have a name, which makes them accessible in the *.cs/vb file. You set the textBox2 binding in the XAML file and the data context in the code behind:
Open in new window
sample = "ABC DEF GHI JKL MNO PQR";
// assign directly to the Text property
tb1.Text = sample;
// register with the binding system
tb2.DataContext = sample;
// there must also be a binding in the XAML
// or here in code
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.