0
votes

I am developing a C# app of this type: WPF/Prism/Unity (MVVM, regions, modularity, a custom RegionAdapterBase for a Telerik RadDocking control (at the RadDocking level, NOT pane group level) and a pane factory for mapping out which pane group (left right bottom) where a tab should appear).

Question:

Everything is good except the DocumentHost. I can get documents to show up there but they all end up having the same tab title. Can you help me understand why this might be?

More background info:

For all documents in the DocumentHost, I have a single module which references a view/viewmodel. The view has a textbox for a query over a datagrid for the table data returned by a query in the textbox. Think SQL Server Mgmt Studio, right click a table and choose select to view data in a table.

screenshot

When the user right clicks a table, I have a command bound to a context menu "Select Data" option on the "Explorer" pane and the command contains this code:

_container.Resolve<SqlAndDataGridModule>(new DependencyOverride<IConversionExplorerObject>(obj)).Initialize();

What's with "obj"? I'm trying to pass the name of the table I clicked on to the document module so I can set the tab title. Again, this works except for the "overwrite all tabs titles" issue. All tabs are titled with the most recent one I open.

So the SqlAndDataGridModule has an initialize in which I do this:

public void Initialize()
{
    // Register view and view model types
    _container.RegisterType<SqlAndDataGrid>();
    _container.RegisterType<ISqlAndDataGridView_ViewModel, SqlAndDataGridView_ViewModel>();

    // Create a view model
    SqlAndDataGridView_ViewModel s = new SqlAndDataGridView_ViewModel(_repository, _eventAggregator, _manager);

    // Set the property TabTitle to table's name
    // This property is bound to RadDocumentPane's header
    s.TabTitle = ((ConversionExplorerObject)_explorerObject).Name;

    // Create view and inject the view model with the tab title
    SqlAndDataGrid sv = _container.Resolve<SqlAndDataGrid>(new DependencyOverride<ISqlAndDataGridView_ViewModel>(s));

    // Register the instance in the container
    _container.RegisterInstance(s.TabTitle, sv);

    // Register the view with the DockRegion
    _manager.RegisterViewWithRegion(RegionNames.DockRegion, () => _container.Resolve<SqlAndDataGrid>(s.TabTitle));
}

I have confirmed that I am creating separate views and view models and I can even see the different tab titles in the debugger. But it seems like somewhere in the binding to the pane header, something is going wrong.

I believe this is a binding issue and not a Telerik issue which is why I'm posting here and not there. Any help is appreciated and I'll be glad to give any more information if it will help. Thanks, Chris

1

1 Answers

0
votes

I figured out my issue. In case this helps anyone, my problem was that in my SqlAndDataGridModule's view model I had subscribed to the "select all rows" event. This means that each instance of the view model (one for each tab) was subscribed to the event and every view model was binding to the newly selected explorer object.

I should only have subscribed from the shell's view model since that is where I instantiate a new instance of the SqlAndDataGridModule (and its view/viewmodel). Moral of the story - beware of what events are published and how you subscribe to them.