nlobak
nlobak

Reputation: 103

Binding textbox in wpf

I have implemented the binding using the answer posted here: WPF Binding to local variable and this: https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx

It looks like this:

public partial class AddCard: DXWindow, INotifyPropertyChanged
{
   public event PropertyChangedEventHandler PropertyChanged;
   private int _CardNumber;

   public int CardNumber
   { 
       get { return _CardNumber; }
       set
       {
           if (value != _CardNumber)
           {
              _CardNumber = value;
              OnPropertyChanged("CardNumber");
           }
       }
   }

   private void OnPropertyChanged(string p)
   {
       if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(p));
   }
}

in xaml (I'm using DevExpress components):

    <dx:DXWindow
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
    .../>

<dxe:TextEdit Text="{Binding Path=CardNumber}"/>

The problem: When updating the CardNumber value in code - it updates the text box on the window, BUT updating the textbox in the window - doesn't update the property of CardNumber in code.

What am I missing?

Upvotes: 1

Views: 88

Answers (1)

Mark Feldman
Mark Feldman

Reputation: 16148

By default updates only propagate through when the control loses focus. I suspect you want them to update immediately, in which case add 'UpdateSourceTrigger=PropertyChanged' to your binding.

Upvotes: 2

Related Questions