2012-10-15 7 views
0

나는 VoucherEntity라는 클래스는, "고객", 클래스 CustomerEntity의 객체라는 속성이 포함되어 있습니다, 그래서, 노호 코드가WPF 텍스트 상자 바인딩

.cs 파일에
<TextBox Height="23" IsReadOnly="False" HorizontalAlignment="Stretch" Margin="124,48,174,0" Name="txt_customer" VerticalAlignment="Top" Text="{Binding Path=Customer.Name}" /> 

, 내가 울부 짖는 코드가

_voucher = new VoucherEntity(); 
this.DataContext = _voucher; 

는 처음에, 고객 속성이 후 나는 무엇을 버튼, 나는, 그때, 텍스트 상자가 즉시 표시 할 수 있기를 바랍니다 _voucher CustomerEntity 객체의 고객 속성을 제공하지만 실패합니다한다 클릭 null의 의미 해야 할 것?

답변

0

보기에서 변경 사항을 제외하려면 변경 사항에 대한보기를 알려야합니다.

그래서 그냥 VoucherEntity 클래스에서 INotifyPropertyChanged 인터페이스를 구현하고 고객이

public class VoucherEntity: INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    protected void FirePropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
    } 

    private CustomerEntity _customer; 
    public CustomerEntity Customer 
    { 
     get {return _customer;} 
     set 
     { 
      if (_customer != value) 
      { 
       _customer= value; 
       FirePropertyChanged("Customer"); 
      } 
     } 
    } 
} 
+0

예, 그것은 내 문제를 해결하는 방법의 소품 설정 후 PropertyChanged 이벤트가 발생,하지만 난 그렇게하고 싶지 않아 , 그것은 내 수업을 오염시킬 것이기 때문에, WPF만이 인터페이스가 필요합니다, 다른 방법으로, txt_customer.GetBindingExpression (TextBox.TextProperty) .UpdateSource(); 또한 작동하지만, 나는 CustomerEntity 객체를 VoucherEntity 객체에 주어야합니다 버튼을 클릭하여 고객을 선택하기 전에 –

관련 문제