2010-03-16 2 views
2

Je veux supprimer tous les affichages de ma région dans Composite. J'utilise Silverlight 4.0.Comment supprimer tous les affichages dans la région dans CompositeWPF/Silverlight

Et malheureusement, ce code se bloque avec OutOfRangeException à l'intérieur de Composite.

 List<object> views = new List<object>(_regionManager.Regions["NavigationRegion"].Views); 

     foreach (object view in views) 
     { 
      _regionManager.Regions["NavigationRegion"].Remove(view); 
     } 

Ceci est mon callstack:

[Code externe]
Microsoft.Practices.Composite.Presentation Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged (System.Collections. Specialized.NotifyCollectionChangedEventArgs e = {} System.Collections.Specialized.NotifyCollectionChangedEventArgs) ligne 102 + 0x24 octets C#
Microsoft.Practices.Composite.Presentation! Microsoft.Practices.Composite.Presentation.Regions.Vi ewsCollection.RemoveAndNotify (System.Collections.IList articles = Count = 1) Ligne 45 + 0x2B octets C#
Microsoft.Practices.Composite.Presentation! Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.UnderlyingCollection_CollectionChanged (objet expéditeur = Count = 0, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = { System.Collections.Specialized.NotifyCollectionChangedEventArgs}) ligne 153 + 0xb octets C# [code externe]
de Microsoft.Practices.Composite.Presentation! Microsoft.Practices. Composite.Presentation.Regions.Region.Remove (objet view = {Kite.MyApp.SlUI.NavigationRegion.NavigationRegionView}) Ligne 230 + 0x1b octets C#
MyApp.SlUI! Kite.MyApp.SlUI.Components.ViewController.linksRegion_LanguageChanged (objet expéditeur = {} Kite.MyApp.SlUI.Controls.LinksUserControl, Kite.MyApp.SlUI.Common.EventArgs e = { Kite. MyApp.SlUI.Common.EventArgs}) ligne 77 + 0x2D octets C#
MyApp.SlUI! Kite.MyApp.SlUI.Controls.LinksUserControl.OnLanguageChanged (string newlanguage = "fr-fR") ligne 37 + 0x32 octets C#
MyApp.SlUI! Kite.MyApp.SlUI.Controls.LinksUserControl.ComboBox_SelectionChanged (objet expéditeur = {} System.Windows.Controls.ComboBox, System.Windows.Controls.SelectionChangedEventArgs e = { System.Windows.Controls.SelectionChangedEven tArgs}) Ligne 31 + 0xb octets C# [Code externe]

Qu'est-ce que j'ai fait?

P.S. Dans ma région j'ai 3 vues. Ainsi, des accidents composites sur l'enlèvement de la troisième.

En espérant vous aider :). Je vous remercie. UPD: J'ai téléchargé les symboles de débogage et j'ai trouvé que le problème se situait uniquement dans le contrôle d'Accordion en tant que région. Ce est pleine pile d'appel:

mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument argument, System.ExceptionResource resource) + 0x41 bytes 
mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException() + 0x10 bytes 
mscorlib.dll!System.Collections.Generic.List<object>.this[int].get(int index = 0) + 0x13 bytes 
System.Windows.dll!System.Windows.Controls.ItemCollection.GetItemImpl(int index) + 0x15 bytes 
System.Windows.dll!System.Windows.Controls.ItemCollection.GetItemImplSkipMethodPack(int index) + 0xb bytes 
System.Windows.dll!System.Windows.PresentationFrameworkCollection<System.__Canon>.this[int].get(int index) + 0xb bytes 
System.Windows.Controls.Layout.Toolkit!System.Windows.Controls.Accordion.UnselectItem(int index = 0, object item = null) + 0x1aa bytes 
System.Windows.Controls.Layout.Toolkit!System.Windows.Controls.Accordion.ChangeSelectedIndex(int oldIndex = 0, int newIndex = -1) + 0x14c bytes 
System.Windows.Controls.Layout.Toolkit!System.Windows.Controls.Accordion.OnSelectedIndexPropertyChanged(System.Windows.DependencyObject d = {System.Windows.Controls.Accordion}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) + 0x1d9 bytes 
System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications(System.Windows.DependencyProperty dp = {System.Windows.CustomDependencyProperty}, object oldValue, object newValue) + 0x51 bytes  
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation) + 0xf5 bytes  
System.Windows.dll!System.Windows.DependencyObject.SetValueInternal(System.Windows.DependencyProperty dp, object value, bool allowReadOnlySet) + 0x2ad bytes  
System.Windows.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0xb bytes 
System.Windows.Controls.Layout.Toolkit!System.Windows.Controls.Accordion.SelectedIndex.set(int value = -1) + 0x4d bytes 
System.Windows.Controls.Layout.Toolkit!System.Windows.Controls.Accordion.OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) + 0x737 bytes  
System.Windows.dll!System.Windows.Controls.ItemsControl.OnItemCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x52 bytes 
System.Windows.dll!System.Windows.Controls.ItemCollection.NotifyCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x37 bytes 
System.Windows.dll!System.Windows.Controls.ItemCollection.NotifyItemsCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x1f bytes 
System.Windows.dll!System.Windows.Controls.ItemCollection.EnumerableCollectionView.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x4f bytes  
System.Windows.dll!System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x3d bytes 
Microsoft.Practices.Composite.Presentation!Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 102 + 0x24 bytes C# 
Microsoft.Practices.Composite.Presentation!Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.RemoveAndNotify(System.Collections.IList items = Count = 1) Line 45 + 0x2b bytes C# 
Microsoft.Practices.Composite.Presentation!Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.UnderlyingCollection_CollectionChanged(object sender = Count = 0, System.Collections.Specialized.NotifyCollectionChangedEventArgs e = {System.Collections.Specialized.NotifyCollectionChangedEventArgs}) Line 153 + 0xb bytes C# 
System.Windows.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + 0x37 bytes 
System.Windows.dll!System.Collections.ObjectModel.ObservableCollection<System.__Canon>.RemoveItem(int index) + 0xa1 bytes 
mscorlib.dll!System.Collections.ObjectModel.Collection<Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata>.Remove(Microsoft.Practices.Composite.Presentation.Regions.ItemMetadata item) + 0x75 bytes 
Microsoft.Practices.Composite.Presentation!Microsoft.Practices.Composite.Presentation.Regions.Region.Remove(object view = {Kite.MyApp.SlUI.NavigationRegion.NavigationRegionView}) Line 230 + 0x1b bytes C# 

Répondre

5

Commencerpars'assurerqu'iln'yaplus _regionManager.Régions [ « NavigationRegion »] existe et est non nul comme si

if (_regionManager.Regions["NavigationRegion"] != null) 
{ 
     List<object> views = new List<object>(_regionManager.Regions["NavigationRegion"].Views); 

     foreach (object view in views) 
     { 
      _regionManager.Regions["NavigationRegion"].Remove(view); 
     } 
} 

Il se peut que NavigationRegion isnt mis en place correctement, ou il y a une faute de frappe ou quelque chose comme ça

2

utiliser une boucle non foreach lors de la modification d'une collection

+0

pourquoi ??? c'est tout le but de foreach - iterating IEnumerables ... – barrypicker

1

si vous voulez supprimer un seul, vous pouvez faire:

_regionManager.Regions["NavigationRegion"].Remove(
        _regionManager.Regions["NavigationRegion"].GetView("viewName")); 
Questions connexes