This is a migrated thread and some comments may be shown as answers.

RadPane's Close event when a modelView used by multiple views

4 Answers 205 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Mahlatse
Top achievements
Rank 1
Mahlatse asked on 12 Oct 2016, 09:46 AM

I am failry new to telerik and WPF and MVVM, so please forgive my lack on knowledge, I have a Shell that that uses directory searching to find modules that I can load into its regions, Each module has a few views that are have top level elementa radSplitContainer, A few of those views can be opened at one time and each has custom logic when the RapPane is closed

 

What I did was used event aggregation to publish the closed event, but I cant find a way to know what view called the close event without creating a reference to my view inside my viewmodell. I have tried 

 

 private void DockMain_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)<br>        {<br>            if (e.Panes != null && e.Panes.Count() > 0 && e.Panes.ToList()[0].GetType() == typeof(RadPane))<br>            {<br>                if (_mainviewmodel != null)<br>                {<br>                    var test = e.Panes.ToList()[0].ParentOfType<RadSplitContainer>();<br>                    var bol = test.GetType().IsAssignableFrom(typeof(IModuleView));<br>                    //var test = e.Panes.ToList()[0].ParentOfType<RadSplitContainer>();<br>                    _mainviewmodel.OnPreviewClose(e.Panes.ToList()[0].ParentOfType<RadSplitContainer>() as IModuleView);//publish teh subscriber event<br>                }<br>            }<br>        }

 

to try and create an interface that both the view and viewModel would implement, but i can never find an object that supports the interface I just created or anyway I can tap into the close event  from the view instead of from the RapDock control.

4 Answers, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 14 Oct 2016, 03:04 PM
Hi Mahlatse,

The desired utilization depends a lot on the specific implementation of the project.

I assume that you might have set the ViewModel which you wish to get in the RadDocking.PreviewClose event is as DataContext for the specific view. If I am correct I suggest getting the ViewModel from the RadDocking:
private void DockMain_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
{
    var docking = e.Source as RadDocking;
    if (docking != null)
    {
        var viewModel = docking.DataContext as ViewModel;
        // call desired method from the viewModel
    }
     
    // if (e.Panes != null && e.Panes.Count() > 0 && e.Panes.ToList()[0].GetType() == typeof(RadPane))
    // {
    //  if (_mainviewmodel != null)
    //  {
    //      var test = e.Panes.ToList()[0].ParentOfType<RadSplitContainer>();
    //      var bol = test.GetType().IsAssignableFrom(typeof(IModuleView));
    //      //var test = e.Panes.ToList()[0].ParentOfType<RadSplitContainer>();
    //      _mainviewmodel.OnPreviewClose(e.Panes.ToList()[0].ParentOfType<RadSplitContainer>() as IModuleView);//publish teh subscriber event
    //  }
    // }
}

If my assumption is incorrect and the proposed approach does not help I will ask for more information regarding your scenario - are you using PanesSource or Prism or none, how is the ViewModels setup and how are they used?

You can take a look at our QSF examples: http://demos.telerik.com/wpf/ and our Developer focused examples: https://github.com/telerik/xaml-sdk/tree/master/Docking for different approaches for setting up the RadDocking.
 
Regards,
Polya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Mahlatse
Top achievements
Rank 1
answered on 18 Oct 2016, 09:39 AM

My biggest Issue is that the dock has a different DataContext than the RadPane, I am using Prism to load the Views with MEF and when I try the above approach, my ViewModel is null. What I have essential done is made the viewModel to implement an interface that I would use to call its close method.

 

private void DockMain_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
        {
             if (e.Panes != null && e.Panes.Count() > 0 && e.Panes.ToList()[0].GetType() == typeof(RadPane))
            {
                if (_mainviewmodel != null)
                {
                    //var test = e.Panes.ToList()[0].ParentOfType<RadSplitContainer>();
                    var _view = e.Panes.ToList()[0].ParentOfType<RadSplitContainer>();//publish teh subscriber event
                    if (_view != null)
                    {
                        var _viewModel = _view.DataContext as IModuleViewModel;
                        if (_viewModel != null)
                        {
                            _viewModel.ModuleView.CloseUserController();
                        }
                    }
                }
            }
        }

 

Where IModuleViewModel has a type of IModuleView that in-turn has a property called View, I use the property to set the current view and then call its CloseUserControl method, but the IModuleViewMoel is null. So I cant use that approach

0
Polya
Telerik team
answered on 20 Oct 2016, 01:35 PM
Hello Mahlatse,

As I understand you wish to call the CloseUserController() from the ViewModel that is used as DataContext for the RadSplitContainer holding the closed RadPane.
If the problem lies in the fact that this DataContext is lost, I am afraid the reason might lie in the application implementation which is unavailable to us.
The only thing I can suggest is that possibly the DataContext of a RadPane is lost when it is made floating, because in that floating action the following process is executed:
  • The RadPane is removed from its parent RadPaneGroup
  • That RadPaneGroup is removed from its parent RadSplitContainer
  • A new RadSplitContainer and RadPaneGroup are created
  • The RadPane is added to that RadPaneGroup
  • The group is added to the RadSplitContainer
  • Finally the container is added to a freshly created ToolWindow.
You can take a look at this blog post which provides an runnable example of the best practices when using RadDocking with PRISM. You can find the example project directly here.

Regards,
Polya
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Mahlatse
Top achievements
Rank 1
answered on 25 Oct 2016, 07:00 AM
Thanks, for now I will see if I can use the headers to accommodate the application until i get a better solution or change the project. 
Tags
Docking
Asked by
Mahlatse
Top achievements
Rank 1
Answers by
Polya
Telerik team
Mahlatse
Top achievements
Rank 1
Share this question
or