Exception with RibbonRegionAdapter

Topics: Prism v4 - WPF 4
Jan 4, 2012 at 10:28 AM

Hi All,

When i try to remove the view of RibbonTab. I am getting follwing exception can any one help me on this.

Follwing code is used for adding and removing the RibbonTabs :

  protected override void Adapt(IRegion region, Ribbon regionTarget)
           {
               region.Views.CollectionChanged += (sender, e) =>
               {
                   switch (e.Action)
                   {
                       case NotifyCollectionChangedAction.Add:
                           foreach (FrameworkElement element in e.NewItems)
                           {
                               regionTarget.Items.Add(element);
                           }
                           break;

                       case NotifyCollectionChangedAction.Remove:
                           foreach (UIElement elementLoopVariable in e.OldItems)
                           {
                               var element = elementLoopVariable;
                               if (regionTarget.Items.Contains(element))
                               {
                                   regionTarget.Items.Remove(element);
                               }
                           }
                           break;
                   }
               };
           }

when i try to remove the tab i am getting following exception :

" {"The region does not contain the specified view.\r\nParameter name: view"} "

 

Stack Trace :

   at Microsoft.Practices.Prism.Regions.Region.GetItemMetadataOrThrow(Object view)
   at Microsoft.Practices.Prism.Regions.Region.Remove(Object view)
   at Microsoft.Practices.Prism.Regions.Behaviors.RegionMemberLifetimeBehavior.OnActiveViewsChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.NotifyRemove(IList items, Int32 originalIndex)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.RemoveFromFilteredList(Object item)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.Remove(T item)
   at Microsoft.Practices.Prism.Regions.Region.Remove(Object view)
   at PCSchool.Library.Views.LibraryQATView.ClearViews(IRegionManager rmanager) in F:\PCSchoolFinalProject\PCSchool\PCSchool.Library\Views\LibraryQATView.xaml.cs:line 83
   at PCSchool.Library.Views.LibraryQATView.RibbonQuickAccessToolBar_Loaded(Object sender, RoutedEventArgs e) in F:\PCSchoolFinalProject\PCSchool\PCSchool.Library\Views\LibraryQATView.xaml.cs:line 38
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at PCSchool.App.Main() in F:\PCSchoolFinalProject\PCSchool\PCSchool\obj\x86\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Thanks and Regards,

Sakthi

Developer
Jan 4, 2012 at 5:23 PM

Hi,

Since we are already treating this subject which is related to this other thread, it would be helpful if we could continue the discussion there.

Thanks,

Agustin Adami
http://blogs.southworks.net/aadami