2013-02-03 20 views
0

我有一個用戶控件的列表框,每個用戶控件都顯示有界數據的屬性,並且當自定義控件更改數據時UI未更新,將集合綁定到自定義控件。如下:當屬性發生變化時,不會更新用戶界面的嵌套集合

ObservableCollection<Subscription> subscriptions = new ObservableCollection<Subscription> SubscriptionRepository.GetSubscriptions()); 
      SubListBox.ItemsSource = subscriptions; 

XAML:

<DataTemplate x:Key="MyDataTemplate"> 
      <UserControls:SubscriptionUC /> 
</DataTemplate> 

<ListBox x:Name="SubListBox" ItemTemplate="{StaticResource MyDataTemplate}"> 
</ListBox> 

用戶控制:

<TextBlock Text="{Binding Path=DaysAttended}" /> 
<cc:CustomControl SubscriptionSource="{Binding Path=SubscriptionDays,Mode=TwoWay}" /> 

訂閱類:

public class Subscription : INotifyPropertyChanged 
    { 
     public int SubscriptionTypeId { get; set; } 

     public DateTime StartDate { get; set; } 

     public DateTime EndDate { get; set; } 

     public ObservableCollection<SubscriptionDay> SubscriptionDays { get; set; } 

     public int DaysAttended { get { return SubscriptionDays.Count(d => d.Attended == true); } } 
public void DayChanged() 
     { 
      RaisePropertyChanged("SubscriptionDays"); 
      RaisePropertyChanged("DaysAttended"); 
     } 
} 

DayChanged()從SubscriptionDay類時SubscriptionDay改變性質,它被稱爲但是DaysAttended沒有更新調用。

回答

0

你還需要有二傳手DaysAttended屬性,雙向綁定是必須的,你的財產應該有getter和setter。我希望這會有所幫助。

+0

我很抱歉,但沒有奏效。我試圖在一個測試項目中做出同樣的想法,它正在工作我不知道我的項目中存在什麼問題! –

相關問題