2013-12-12 34 views
0

我有一個自定義類,usercontrol在其代碼後面實現了一個依賴項屬性。具有依賴項屬性的用戶控件無法識別更改

public partial class HandControl 
{ 
    public HandControl() 
    { 
     InitializeComponent(); 
    } 

    public Seat Seat 
    { 
     get 
     { 
      return (Seat)GetValue(SeatProperty); 
     } 
     set 
     { 
      SetValue(SeatProperty, value); 
     } 
    } 

    public static readonly DependencyProperty SeatProperty = DependencyProperty.Register("Seat", typeof(Seat), typeof(HandControl), new PropertyMetadata(null)); 
} 

在我的情況下,我已經將該類中的name屬性綁定到usercontrols xaml中的標籤。

<Label Content="{Binding Seat.Player.Name, RelativeSource={RelativeSource AncestorType={x:Type controls:HandControl}}}"/> 

我的窗口視圖模型包含屬性SeatTl和XAML綁定到它:

public Seat SeatTr 
    { 
     get { return _seatTr; } 
     private set 
     { 
      _seatTr = value; 
      OnPropertyChanged(); 
     } 
    } 

    <customControls:HandControl Grid.Row="1" 
           Grid.Column="3" 
           Seat="{Binding SeatTr}" /> 

但是,當我改變我的課的內容(name屬性)和手動提高OnPropertyChanged我的viewmodel(不是usercontrol),標籤不更新,仍然有相同的內容。

private void OnSeatChanged(Player player, SeatPosition seatPosition) 
    { 
     //... doing the changes ...\\ 
     OnPropertyChanged("SeatTr"); 
    } 

我的問題是什麼?任何人都有線索?

回答

1

我覺得你應該爲Seat.Player.Name屬性引發OnPropertyChanged,因爲它正在被chaged。

+0

沒錯,那是我的問題。我還必須將INotifyPropertyChanged實現到我的座椅類中。 – Jannik

相關問題