RadDocumentaPane : Close all but this issue

9 posts, 0 answers
  1. Jeremie
    Jeremie avatar
    7 posts
    Member since:
    Jun 2011

    Posted 28 Jun 2011 Link to this post

    Hello,

    I have a problem with the RadDocumentPane.

    I want to offer a new RadContextMenu on my RadDocumentPanes (because I don't want the default Telerik RadContextMenu).

    So when I load a new RadDocumentPane, I create a new RadContextMenu on it :

            
    void RadDocumentPaneLoaded(object sender, System.Windows.RoutedEventArgs e)
    {
        // Cast the sender
        RadPane radPane = (RadPane)sender;
        if (radPane.IsNotNull() && radPane.Content.IsNotNull())
        {
            // Just destroy the current ContextMenuTemplate (the telerik default context Menu) to instancie a new one
            radPane.ContextMenuTemplate = null;
            // Instanciate a new one
            RadContextMenu radContextMenu = new RadContextMenu();
            // Instanciate the command : close all radpane but this
            RadMenuItem closeAllButThisCommand = new RadMenuItem()
            {
                Command = new DelegateCommand<RadContextMenu>(this.CloseAllButThis),
                CommandParameter = radContextMenu,
                Header = "Close all but this"
            };
            radContextMenu.Items.Add(closeAllButThisCommand);
            // Actually, set the new context menu to the radPane we loading
            RadContextMenu.SetContextMenu(radPane, radContextMenu);
        }
    }

    Then, I define my Action for the this.CloseAllButThis() Method :

    private void CloseAllButThis(RadContextMenu radContextMenu)
            {
                // First, get the RanePaneGroup which contains all the RadPan
                RadPaneGroup radPaneGroup = radContextMenu.GetClickedElement<RadDocumentPane).GetVisualParent<RadPaneGroup>();
      
                // Also get the pane where the user right click
                RadDocumentPane keepDocumentPane = radContextMenu.GetClickedElement<RadDocumentPane>();
      
                // Then, we gets all the radpane instanciate in the radpaneGroup into a ItemCollection
                ItemCollection currentRadPanes = radPaneGroup.Items;
      
                // Iterate on the itemcollection
                for (int i = 0; i < currentRadPanes.Count; i++)
                {
                    if (!(currentRadPanes[i] as RadDocumentPane).Equals(keepDocumentPane))
                    {
                        ((RadDocumentPane)currentRadPanes[i]).RemoveFromParent();
                    }
                }

    But the following error occures (on the RemoveFromParent(); ) :

    {System.Exception: Une erreur HRESULT E_FAIL a été retournée à partir d'un appel à un composant COM.
       à MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       à MS.Internal.XcpImports.Collection_RemoveAt[T](PresentationFrameworkCollection`1 collection, UInt32 index)
       à System.Windows.PresentationFrameworkCollection`1.RemoveAtImpl(Int32 index)
       à System.Windows.Controls.ItemCollection.RemoveAtImpl(Int32 index)
       à System.Windows.Controls.ItemCollection.RemoveImpl(Object value)
       à System.Windows.Controls.ItemCollection.RemoveInternal(Object value)
       à System.Windows.PresentationFrameworkCollection`1.Remove(T value)
       à Telerik.Windows.Controls.RadPaneGroup.RemovePane(RadPane pane)
       à Telerik.Windows.Controls.RadPane.RemoveFromParent()
       à Vcf.Common.Core.Layout.DockingLayoutManager.CloseAllButThis(RadContextMenu radContextMenu)
       à Vcf.Common.Core.DelegateCommand`1.Execute(Object parameter)
       à Telerik.Windows.Controls.RadMenuItem.ExecuteCommand()
       à Telerik.Windows.Controls.RadMenuItem.OnClickImpl()
       à Telerik.Windows.Controls.RadMenuItem.OnClick()
       à Telerik.Windows.Controls.RadMenuItem.ClickItem()
       à Telerik.Windows.Controls.RadMenuItem.HandleMouseUp()
       à Telerik.Windows.Controls.RadMenuItem.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       à System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
       à MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}


    Can you give me some help ?

    Regards

    Jeremie
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 30 Jun 2011 Link to this post

    Hello Jeremie,

     I tried the code you provided and it seems it works without throwing an exception, but it doesn't remove all the panes. Could you please try the following code which works fine in my sample project:

    var parent = pane.PaneGroup;
     
    foreach (var otherPane in parent.EnumeratePanes().Where(p => p != pane).ToArray())
    {
        otherPane.RemoveFromParent();
    }

    If this doesn't help you to resolve the problem, could you please provide a sample project that reproduces the issue - this would help use to identify what exactly goes wrong.

    Kind regards,
    Miroslav Nedyalkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Jeremie
    Jeremie avatar
    7 posts
    Member since:
    Jun 2011

    Posted 30 Jun 2011 Link to this post

    Thanks for your reply !

    I tried your code sample but the H_RESUL FAILED is the same error on the RemoveFromParent() method.

    {System.Exception: Une erreur HRESULT E_FAIL a été retournée à partir d'un appel à un composant COM.
       à MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       à MS.Internal.XcpImports.Collection_RemoveAt[T](PresentationFrameworkCollection`1 collection, UInt32 index)
       à System.Windows.PresentationFrameworkCollection`1.RemoveAtImpl(Int32 index)
       à System.Windows.Controls.ItemCollection.RemoveAtImpl(Int32 index)
       à System.Windows.Controls.ItemCollection.RemoveImpl(Object value)
       à System.Windows.Controls.ItemCollection.RemoveInternal(Object value)
       à System.Windows.PresentationFrameworkCollection`1.Remove(T value)
       à Telerik.Windows.Controls.RadPaneGroup.RemovePane(RadPane pane)
       à Telerik.Windows.Controls.RadPane.RemoveFromParent()
       à Vcf.Common.Core.Layout.DockingLayoutManager.CloseAllButThis(RadContextMenu radContextMenu)
       à Vcf.Common.Core.DelegateCommand`1.Execute(Object parameter)
       à Telerik.Windows.Controls.RadMenuItem.ExecuteCommand()
       à Telerik.Windows.Controls.RadMenuItem.OnClickImpl()
       à Telerik.Windows.Controls.RadMenuItem.OnClick()
       à Telerik.Windows.Controls.RadMenuItem.ClickItem()
       à Telerik.Windows.Controls.RadMenuItem.HandleMouseUp()
       à Telerik.Windows.Controls.RadMenuItem.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       à System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
       à MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}
  5. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 01 Jul 2011 Link to this post

    Hi Jeremie,

    We investigated the issued and found out that the problem is the ContextMenu you are attaching. The right way to do this is to use ContextMenuTemplate property of the RadPane control.

    The issue you are observing could be fixed by just changing the CloseAllButThis method this way:

    private void CloseAllButThis(object menu)
    {
        var radContextMenu = menu as RadContextMenu;
        var pane = radContextMenu.GetClickedElement<RadPane>();
        var parent = pane.PaneGroup;
     
        foreach (var otherPane in parent.EnumeratePanes().Where(p => p != pane).ToList())
        {
            RadContextMenu.SetContextMenu(otherPane, null);
            otherPane.RemoveFromParent();
        }
    }

    Hope this helps.

    Regards,
    Miroslav Nedyalkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Jeremie
    Jeremie avatar
    7 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2011 Link to this post

    Thanks for your answer !

    It's seem to be all right for me :)

    Thank you very much.
  7. Jeremie
    Jeremie avatar
    7 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2011 Link to this post

    OK I spoke to fast !

    Now, my new Right Click ContextMenu works done.

    But, when I want to close just one RadPane with the command :
    telerik:RadDockingCommands.Close

    I have this big error message

    à System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    à System.Delegate.DynamicInvokeImpl(Object[] args)
    à System.Delegate.DynamicInvoke(Object[] args)
    à Telerik.Windows.RadRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
    à Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
    à Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
    à Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
    à Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
    à Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
    à Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
    à Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
    à Telerik.Windows.Controls.RadPane.OnClose(StateChangeCommandEventArgs args)
    à Telerik.Windows.Controls.RadPane.Close()
    à Telerik.Windows.Controls.RadPane.OnIsHiddenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    à Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
    à System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
    à System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
    à System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
    à System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
    à Telerik.Windows.Controls.RadPane.set_IsHidden(Boolean value)
    à Telerik.Windows.Controls.Docking.PaneGroupBase.ExecuteCommand(RadPane pane, ICommand command, PaneGroupBase groupBase)
    à Telerik.Windows.Controls.Docking.PaneGroupBase.<>c__DisplayClass1.<OnPaneCommandInvoke>b__0()


    And the e.ExceptionObject.InnerException.StackTrace :

    à MS.Internal.XcpImports.CheckHResult(UInt32 hr)
    à MS.Internal.XcpImports.Collection_RemoveAt[T](PresentationFrameworkCollection`1 collection, UInt32 index)
    à System.Windows.PresentationFrameworkCollection`1.RemoveAtImpl(Int32 index)
    à System.Windows.Controls.ItemCollection.RemoveAtImpl(Int32 index)
    à System.Windows.Controls.ItemCollection.RemoveImpl(Object value)
    à System.Windows.Controls.ItemCollection.RemoveInternal(Object value)
    à System.Windows.PresentationFrameworkCollection`1.Remove(T value)
    à Telerik.Windows.Controls.RadPaneGroup.CloseSinglePane(RadPane pane)
    à Telerik.Windows.Controls.RadPaneGroup.ClosePane(RadPane pane)
    à Telerik.Windows.Controls.RadDocking.RadPane_Close(Object sender, StateChangeCommandEventArgs args)


    Any idea ?
  8. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 04 Jul 2011 Link to this post

    Hi Jeremie,

     In my opinion this is the same problem - the ContextMenu you assign manually should be removed before removing the pane. We are taking care for the menu we create and attach using the ContextMenuTemplate, but we are not cleaning the one you place. What I would suggest you is to not you the approach with the custom menu, but to use the ContextMenuTemplate instead.

    Hope this helps.

    Greetings,
    Miroslav Nedyalkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Jeremie
    Jeremie avatar
    7 posts
    Member since:
    Jun 2011

    Posted 04 Jul 2011 Link to this post

    Hi,

    Thanks for help.

    I will try to manually remove the contextMenu before removing the pane.

    But if I use this " custom " context menu it's cause the " ContextMenuTemplate " don't works (and I don't know why).
  10. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 07 Jul 2011 Link to this post

    Hi Jeremie,

     The problem is that you need to remove your custom ContextMenu from the pane just before closing, which is not done by the default Close command. You could use the PreviewClose event of the Docking control for this purpose.

    Hope this helps.

    Kind regards,
    Miroslav Nedyalkov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
DevCraft banner