1
Answer

Can someone help me - (Binding - Code behind)

I want to Bind a Textbox Value to a .NET Class in C# Code but it didn´t works :(

1. The Aim should be FieldName

 public class DataClass : INotifyPropertyChanged
    {
        private string _FieldName;

        public string FieldName
        {
            get { return _FieldName; }
            set
            {
                if (_FieldName == value) return;
                _FieldName = value;
                OnPropertyChanged("Text");
            }
        }

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

2. This is the Binding: (name of the Textbox:txtName_)

Event MainWindow Loaded:

            DataAim = new DataClass();

            Binding myBinding = new Binding();
            myBinding.Path = new PropertyPath("Text");
            myBinding.Source = DataAim;
            myBinding.Mode = BindingMode.TwoWay;
            myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

            txtName_.SetBinding(TextBox.TextProperty, myBinding);

Can someone tell me what is wrong ?


Answers (1)