Created one custom WPF control with a textbox. We can bind the custom WPF control to data in different ways.
Bind Using Class Object
Xaml
Code Behind
1. Create object of the class Address like
Address add=new Address(){Street=”Hyderabad Eat Street”};
2. Assign to DataContext of the user control
userControl11.DataContext = add;
Bind Using Dictionary
When binding using a dictionary object, we are binding to an element using the string key; so the key should be inside square brackets.
Xaml
<textbox height="23" margin="139,26,0,0" name="textBox1" width="157" text="{Binding [Street], Mode=TwoWay}”>
Code Behind
1. Create the Dictionary Object
Dictionary data = new Dictionary();
data.Add(“Street”, “Hyderabad Eat Street”);
2. Assign to DataContext of the user control
userControl11.DataContext = data;