You can uses so called Properties with public getters and setters and bind that to the textbox
public class MainViewModel : NotificationObject
{
public MainViewModel()
{
Person = new Person();
SaveCommand = new DelegateCommand(SaveExecuted);
}
// Properties
public Person Person { get; set; }
// Commands
public ICommand SaveCommand { get; set; }
private void SaveExecuted()
{
// Do some save logic here!
}
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
And in your textbox XAML
<TextBox Text="{Binding Person.FirstName}" />
<Button Command="{Binding SaveCommand}" Content="Save"/>
And in the codebehind add this line
public MainWindow()
{
InitializeComponent();
DataContext = new MainViewModel(); //Add this line
}
something like that
dont forget to set the DataContext of the View to itself or another public object you want to use the properties of.
also take a look at MVVM nice way to use WPF and use separation of conserns
Make a button on you View called Save and Band this button to a Command like you do with the other properties
And in the Execute method save to the Database or update.
the NotificationObject and DelegateCommand are from Prism 4