2012-03-04 8 views
0

エンドユーザーに広告を表示するTelerik TransitionControlがあります。ロジックは、広告イメージが非同期で後ろにダウンロードされるように書き込まれます。コントロールは使用可能なイメージを表示します。 ObservableCollectionを使用して広告イメージを保持しています。イメージが正常にダウンロードされると、新しいObservableCollectionにイメージ情報が追加されます。しかし、Telerik TransitionControlは新しい画像で更新されていません。ObservableCollectionがコントロールを更新していません

私は

コードが

//Inside the AdvertUserControl.xaml.cs 

ViewModel vm = new ViewModel(); 
DataContext = vm; 

this.radControl.SetValue(AdRotatorExtensions.AdRotatorExtensions.ItemsSourceProperty, vm.SquareAdsVertical); 

// ViewModel.csインサイドの下に与えられている内部的に呼び出されるようOnNotifyPropertyChangedを必要としないのObservableCollectionが呼び出されると信じて

public ReadOnlyObservableCollection<Advert> SquareAdsVertical 
     { 
      get 
      { 
       if (AdsManager.VerticalAds == null) 
       { 

        return null; 
       } 
       return new ReadOnlyObservableCollection<Advert>(AdsManager.VerticalAds); 
      } 
     } 


// Inside DownloadManager.cs 
    private static ObservableCollection<Advert> adsToShowVertical = new ObservableCollection<Advert>(); 
public static ObservableCollection<Advert> VerticalAds 
     { 
      get { if (adsToShowVertical != null) return adsToShowVertical; 
       return null; 
      } 
     } 

public static void OnDownloadComplete(Object sender, AsyncCompletedEventArgs e) 
{ 
     try 
     { 


    if(!e.Cancelled) 
    { 

     if (e.Error == null) 
     { 
      Advert ad = e.UserState as Advert ; 
     adsToShowVertical.Add(ad ); 
     } 

} 

答えて

0

observableコレクションから作成された読み取り専用コレクションのインスタンスを1つだけ返す必要があります。 Observableの値を変更すると、コントロールはreadonlyコレクションを通じて更新されます。

1

私はTelerikのコントロールを使用していないが、私はあなたが以下の

private ReadOnlyObservableCollection<Advert> _readonlyAds; 
public ReadOnlyObservableCollection<Advert> SquareAdsVertical 
{ 
    get 
    { 
     if (AdsManager.VerticalAds == null) 
     { 
      return null; 
     } 
     else if (_readonlyAds == null) 
     { 
      // Only one instance of the readonly collection is created 
      _readonlyAds = new ReadOnlyObservableCollection<Advert>(AdsManager.VerticalAds); 
     } 

     // Return the read only collection that wraps the underlying ObservableCollection 
     return _readonlyAds; 
    } 
} 
ためにあなたのビューモデル

public ReadOnlyObservableCollection<Advert> SquareAdsVertical 
{ 
    get 
    { 
     if (AdsManager.VerticalAds == null) 
     { 
      return null; 
     } 
     return new ReadOnlyObservableCollection<Advert>(AdsManager.VerticalAds); 
    } 
} 

に次のコードを変更した場合と思われます

関連する問題