I have a property (MainStudent) in my Page class:
public partial class AddStudent : Page
{
public AddStudent()
{
InitializeComponent();
MainStudent = new Student();
}
public Student MainStudent
{
get;
set;
}
}
What is the best way to bind FirstName property of MainStudent Property (Student Class has some methods. For example: FirstName, LastName.) to Text property of TextBox in XAML?
If your
Pagehas properties that refer only toStudentyou can set itsDataContextdirectly there, as last line in your current constructor:and then in XAML do bindings directly to the properties of Student:
Or else your can set the DataContext of your
Pageto itself:and do bindings like: