Remove RadDocumentPane from PRISM region when closed

2 posts, 1 answers
  1. Marcel
    Marcel avatar
    41 posts
    Member since:
    Jan 2014

    Posted 30 Jul 2015 Link to this post

    Hello,

    I am trying to remove a RadDocumentPane from a region when its closed, but I cant find a way to catch the close event in my viewmodel?

    Whats the best approach to accomplished this with the Docking control?

     

    Marcel

     

  2. Answer
    Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 04 Aug 2015 Link to this post

    Hello Marcel,

    When a RadPane/RadDocumentPane instance is closed via its "Close" button the Close event of the RadDocking control is raised. In that event you can get the closed instances from the event args Pane collection. When working in a more MVVM scenarios you could use our EventToCommandBehavior in order to bring the Close event handler to the ViewModel. The next code snippet shows how the EventToCommandBehavior could be used in the RadDocking control.

    the ViewModel's code should include something like this:
    public class ViewModel
    {
        public ICommand CustomCommand { get; set; }
     
        public ViewModel()
        {
            this.CustomCommand = new DelegateCommand(OnCustomCommandExecuted);
        }
     
        private void OnCustomCommandExecuted(object obj)
        {
            var args = obj as Telerik.Windows.Controls.Docking.StateChangeEventArgs;
            var closedPanes = args.Panes.ToList();
            foreach (var pane in closedPanes)
            {
                MessageBox.Show(string.Format("{0} pane closed", pane.Header));
     
                // Add your custom logic that removes the instance from the region here.
            }
        }
    }

    and the the XAML code:
    <Window ...
            xmlns:local="clr-namespace:DockingClosedEvent"
             ...>
        <Window.DataContext>
            <local:ViewModel/>
        </Window.DataContext>
        <Grid>
            <telerik:RadDocking>
                <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding Command="{Binding CustomCommand}"
                                          EventName="Close"
                                          PassEventArgsToCommand="True"/>
                </telerik:EventToCommandBehavior.EventBindings>
                 ...
            </telerik:RadDocking>
        </Grid>
    </Window>

    Hope this is helpful.

    Regards,
    Vladi
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top