2010-03-16 3 views
2

Composite에서 내 영역의 모든 뷰를 제거하고 싶습니다. Silverlight 4.0을 사용하고 있습니다.CompositeWPF/Silverlight에서 region의 모든 뷰를 제거하는 방법

그리고 아쉽게도이 코드는 OutOfRangeException with Composite와 충돌합니다. !

[외부 코드]
Microsoft.Practices.Composite.Presentation Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.OnCollectionChanged (은 System.Collections :

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

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

이 내 호출 스택입니다. Specialized.NotifyCollectionChangedEventArgs E = {} System.Collections.Specialized.NotifyCollectionChangedEventArgs) 라인 102 바이트 값 0x24 + C 번호
Microsoft.Practices.Composite.Presentation! Microsoft.Practices.Composite.Presentation.Regions.Vi ewsCollection.RemoveAndNotify (System.Collections.IList 항목 개수 = = 1) 라인 45 + 0x2b 바이트 C#
Microsoft.Practices.Composite.Presentation! Microsoft.Practices.Composite.Presentation.Regions.ViewsCollection.UnderlyingCollection_CollectionChanged (= 오브젝트 발신자 개수 = C 번호 [외부 코드]
Microsoft.Practices.Composite.Presentation! Microsoft.Practices 바이트 + 0xB로 0 System.Collections.Specialized.NotifyCollectionChangedEventArgs E = {} System.Collections.Specialized.NotifyCollectionChangedEventArgs) 라인 (153). Composite.Presentation.Regions.Region.Remove (객체 뷰 = {Kite.MyApp.SlUI.NavigationRegion.NavigationRegionView}) 라인 230 + 0x1b 바이트 C# 0 123, MyApp.SlUI! Kite.MyApp.SlUI.Components.ViewController.linksRegion_LanguageChanged (객체 발신자 Kite.MyApp.SlUI.Controls.LinksUserControl = {} Kite.MyApp.SlUI.Common.EventArgs 전자 = { 연. MyApp.SlUI.Common.EventArgs}) 줄 77 + 0x2d 바이트 C#
MyApp.SlUI! Kite.MyApp.SlUI.Controls.LinksUserControl.OnLanguageChanged (문자열 newLanguage = "ko-GB") 줄 37 + 0x32 바이트 C#
MyApp.SlUI! Kite.MyApp.SlUI.Controls.LinksUserControl.ComboBox_SelectionChanged (객체 발신자 System.Windows.Controls.ComboBox = {} System.Windows.Controls.SelectionChangedEventArgs E = { System.Windows.Controls.SelectionChangedEven tArgs}) 라인 31 + 0xB로 바이트 C#을 [외부 코드] 내가 뭘 잘못했는지

?

P. 내 지역에는 3 개의 의견이 있습니다. 따라서 세 번째 요소를 제거하면 복합 요소가 충돌합니다.

도움을 청하는 중 :). 고맙습니다.

UPD : 디버그 기호를 다운로드했는데 해당 문제가 지역별 Accordion 컨트롤에만있는 것으로 나타났습니다. 이것은 전체 호출 스택입니다.

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# 

답변

5

먼저 _regionManager를 확인하십시오.지역 [ "NavigationRegion은"] 실제로 존재하고 그것은 NavigationRegion가 제대로 설정 또는 foreach는하지 루프가

2

사용 유사한 오타 또는 뭔가가 밤은 것을 할 수 있도록

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); 
     } 
} 

같은 비 null의 경우 모음

+0

왜 ??? 그것은 foreach의 전체 요점입니다 - IEnumerables 반복 ... – barrypicker

1

당신은 단지 하나를 제거하려는 경우를 수정할 때, 당신은 할 수 :

_regionManager.Regions["NavigationRegion"].Remove(
        _regionManager.Regions["NavigationRegion"].GetView("viewName")); 
관련 문제