I Am trying to learn WPF and trying to figure out the best way to bind my LINQ to SQL classes to a WPF window.
so far I have this:
using (Database.DataClasses1DataContext db = new Database.DataClasses1DataContext())
{
var user = db.Users.Where(u => u.Email == TextboxEmail.Text).FirstOrDefault();
CustomerTab.DataContext = user;
}
and in XAML
<TextBox Name="TextboxContactName" Grid.Row="1" Margin="0,2" Grid.Column="1" Text="{Binding Path=ContactName, UpdateSourceTrigger=LostFocus, Mode=TwoWay}"></TextBox>
So this provides a One-Way Bind that displays the name to the textbox.
I have been trying to follow examples online, but my question is, how do I make it update the LINQ Automatically when textbox loses focus.
Do I need to manually enter it in the lost focus event?
edit I have tried to run this when the textbox loses focus:
using (Database.DataClasses1DataContext db = new Database.DataClasses1DataContext())
{
Database.User customer = (Database.User)CustomerTab.DataContext;
db.SubmitChanges();
}
but the Customer Object has no updates to it. I know I could do:
customer.ContactName = textbox.Text;
db.submitChanges();
But I thought WPF was suppose to handle this for me?