Codebehind Binding

SetControlBinding(_config.Data, GetPropertyName<ConfigData, 
    string>(f => f.Username), txtUser);

private void SetControlBinding(object source,
    string propertyPath,
    Control control)
{
    Binding binding = new Binding();
    binding.Source = source;
    binding.Path = new PropertyPath(propertyPath);
    binding.Mode = BindingMode.TwoWay;

    if (control is TextBox)
    {
        control.SetBinding(TextBox.TextProperty, binding);
    }
    else if (control is PasswordBox)
    {
        control.SetBinding(PasswordBox.PasswordCharProperty, binding);
    }
    else if (control is CheckBox)
    {
        control.SetBinding(CheckBox.IsCheckedProperty, binding);
    }
}

public static string GetPropertyName<P, T>(Expression<Func<P, T>> expression)
{
    MemberExpression memberExpression = 
        (MemberExpression)expression.Body;