Binding WPF property dynamically to controls at Design-Time is a good feature provided in WPF. With this feature we can test the control binding without running the application.
Implemention is not a big deal. It is very easy to implement.
I will demonstrate implementation of this feature with an example.
Example:-
Create a new WPF application. Add new project named as "ViewModelBase". Add a class file named as "StudentBase.cs". Add basic properties of Student such as Name, Address, City, State, Country. Refer below image.
Add new project to solution named as "DesignTimeViewModel". Add a class file in that named as "Student.cs". Inherit "StudentBase" to this class. Refer image below...
Add a default constructor to this newly added class. Write a method which sets all the properties of the base class. Call this method from default contructor as shown in above image.
Now, go to the WPF project which was added initially. Double click on Window.Xaml page. Design a page as shown below.
Add binding property to the text box controls shown as selected in the image below. Use respective property such as Name, Address etc for binding to the textbox controls.
After setting binding property to the controls still you will not able to see property value set in derived class in textbox control.
After doing all the above stuff, we required to add one xaml tag in Window section on the Window.xaml page refer a selected tag in the below image.
Now, you will be able to see all the respective properties values set in derived class are dynamically bind to all textbox controls.
Note:- If you are still unable to see property values set in dervied class in textboxes as shown in above image then you must required to build the whole application. If you still face an issue then please le me know.
Hi,
ReplyDeleteThank you very much, this was very usefull for me.
Gud tutorial!!! for a beginner....
ReplyDelete