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

TabControl as region in Prism4 doesn't work as expected for Activate method

7 Answers 247 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Hasan Khan
Top achievements
Rank 1
Hasan Khan asked on 09 Dec 2010, 10:34 PM
If you specify a normal tab control as a region and activate one of the views (already added) then the corresponding tab gets selected.
However if the RadTabControl is used as a region then nothing happens when the view is activated (tab doesn't get selected).
Also all tabs remain active views at all times and IsActive property for ViewModel (that implements IActiveAware) doesn't ever change i.e. on switching tabs.

I could have very well used a normal tab control but I want the expression dark theme which is only available for the RadTabControl.

7 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 15 Dec 2010, 10:50 AM
Hello Hasan Khan,

We are aware of this issue and it is logged in our PITS where you can track its progress and vote for it thus increasing its priority.
In the meantime you can implement this scenario by adding one property called SelectedView and binding the RadTabControl to that view. Please have a look at the attached project for further reference and let me know if this works for you.

Greetings,
Petar Mladenov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Rayne
Top achievements
Rank 1
answered on 02 May 2011, 06:25 PM
I'm not sure how to make this work. In the sample, the shell is controlling the views, so it's easy to get a specific view and make it active. But in my application, I'm adding views to one region from commands on a viewModel in another region and they are in a different project than the shell.

How do I do this from a module project, that has say a button in a toolbar region that when clicked, creates a view, then adds it to the main region and activates it. I do want it to remove the view from the region like it already does. This works, although I had to implement a workaround found in another thread.
0
Tina Stancheva
Telerik team
answered on 05 May 2011, 06:26 PM
Hi Rayne,

Another approach that you can use to workaround this issue is to make sure that the view that is activated is selected. For example when you use the RadTabControl as a region and the views registered in this region are RadTabItems, you can bind each RadTabItem's IsSelected property to a business property. Then, when you activate the RadTabItem view, you can set the business proeprty to True thus selected the activated view.

I attached a sample project illustrating this approach. The Shell project contains a RadTabControl which is defined as a region. The solution contains two modules - each containing a RadTabItem View and a corresponding ViewModel. The ModuleCatalog contains both modules, however Module1 is loaded on demand, therefore only Module2's view is displayed in the RadTabControl region.

The Module2's view contains a button, which will load Module1 into the module catalog and will activate its TabItem view. But it will also set the IsSelected property of the TabItem. This way the new view will be selected when activated.

Take a look at the solution and let us know if it helps.


Kind regards,
Tina Stancheva
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
0
Rayne
Top achievements
Rank 1
answered on 12 May 2011, 10:43 PM
So doing it this way, I have to declare my views as RadTabItem instead of UserControl, which means I can't see the design in the designer. It also means I have an extra layer (a user control on the tab item), then prism creates the tabItem and has to pass values from the datacontext of the tab item to the datacontext of the control that is the content of the tab item.

I switch to TabControl from Docking because I was wanting to avoid having that intermediate control. Any ideas when the fix to this will be, so that I don't have to do all this to get it work as expected? 
0
Tina Stancheva
Telerik team
answered on 18 May 2011, 09:34 AM
Hi Rayne,

Voting for the issue in PITS will definately increase its priority but due to the many pressing tasks in our to-do list, we cannot bind to a date when it will be fixed.

However, if you don't want to change your UserControl views to RadTabItems, you can create a RadTabControl RegionAdapter to manage the definition of the RadTabControl as a region. This will allow you to control the RadTabItems IsSelected property through the adapter.

A sample RadTabControl RegionAdapter definition would look like this:
public class RadTabRegionAdapter : RegionAdapterBase<RadTabControl>
{
    public RadTabRegionAdapter(IRegionBehaviorFactory factory)
        : base(factory)
    {
 
    }
    RadTabControl _regionTarget;
    protected override void Adapt(IRegion region, RadTabControl regionTarget)
    {
        this._regionTarget = regionTarget;
        region.ActiveViews.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ActiveViews_CollectionChanged);
    }
 
    void ActiveViews_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        switch (e.Action)
        {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
            foreach (var item in e.NewItems)
            {
                if (item is RadTabItem)
                    _regionTarget.Items.Add(item);
                else
                {
                    RadTabItem tabItem = new RadTabItem() { Content = item, Header = item.ToString(),IsSelected = true };
                    _regionTarget.Items.Add(tabItem);
                }
            }
            break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
            //implement custom logic
            break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
            //implement custom logic
            break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
            //implement custom logic
            break;
        }
    }
 
    protected override IRegion CreateRegion()
    {
        return new AllActiveRegion();
    }
}
I realize this is yet another workaround but it might help you implement your scenario until the RadTabControl issue is fixed.

Kind regards,
Tina Stancheva
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
0
Kristoffer
Top achievements
Rank 1
answered on 23 Jan 2013, 12:26 PM
Was this ever fixed?!
0
Tina Stancheva
Telerik team
answered on 28 Jan 2013, 11:39 AM
Hello Kristoffer,

Unfortunately this issue isn't addressed yet but you can use the suggested solution - creating a custom RegionAdapter for the RadTabControl. This will solve this issue and allow you to customize the RadTabControl behavior as a region in a modular application to better fit your requirements.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TabControl
Asked by
Hasan Khan
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Rayne
Top achievements
Rank 1
Tina Stancheva
Telerik team
Kristoffer
Top achievements
Rank 1
Share this question
or