Using RegionsManager.RequestNavigate, TabControl is not activating TabItem

Topics: Prism v4 - WPF 4
Aug 24, 2012 at 9:09 AM

I hope I will be able to explain my scenario. 

I've a  Tab control and I've loaded a tab item on the start up. when i click on one of the the row's button, a new tab must open. I'm trying to acheive this using INavigation Aware and MEF.

Deliveries.xaml is default tab. DataPoolView.xaml is the one which should load when i click on any of the row in Deliveries.xaml.

Deliveries.xaml.cs   
 [Export(typeof(Deliveries))]
     [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class Deliveries : UserControl
    {public Deliveries()
        {
            InitializeComponent();
        }

        [Import]
        public IDeliveriesViewModel Model
        {
            get
            {
                return DataContext as IDeliveriesViewModel;
            }
            set
            {
                DataContext = value;
            }
        }
    }

the VM
 [Export(typeof(IDeliveriesViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class DeliveriesViewModel : NotificationObject, IDeliveriesViewModel
    {[ImportingConstructor]
        public DeliveriesViewModel(IRegionManager regionManager, IEventAggregator eventAggregator/*, IDeliveryService deliveryService*/)
        {goToDataPool = new DelegateCommand<string>(NavigateToDataPool);}

private void NavigateToDataPool(string id) 
        {
            var parameters = new UriQuery();
            parameters.Add("datapool", id);
            regionManager.Regions[RegionNames.TabRegion].RequestNavigate(new Uri("/DataPoolView" + parameters.ToString(), UriKind.Relative), NavigationCompleted);
        }

 public ICommand GoToDataPoolCommand
        {
            get
            {                return this.goToDataPool;            }
        }
}

similar to above, I have Datapool.xaml.cs

 [Export("DataPoolView")]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class DataPoolView : UserControl
    {
        public DataPoolView()
        {
            InitializeComponent();
        }

       [Import]
        public IDataPoolViewModel Model
        {
            get{
                return DataContext as IDataPoolViewModel;
            }set
            {
                DataContext = value;
            }
        }

    }

VM of Datapool
[Export(typeof(IDataPoolViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class DataPoolViewModel : NotificationObject, INavigationAware, IDataPoolViewModel
    {
 [ImportingConstructor]
        public DataPoolViewModel(IRegionManager regionManager, IEventAggregator eventAggregator )
        {
            this.regionManager = regionManager;
            this.eventAggregator = eventAggregator;
            //DataPools = new DeliveryService().GetDataPools("ITG");
            headerInfo = "DataPool";
        }
    public void OnNavigatedTo(NavigationContext navigationContext)
        {
            string id = navigationContext.Parameters["datapool"];

            DataPools = new DeliveryService().GetDataPools(id);
            base.RaisePropertyChanged("DataPools");
            
        }
}
Module Class

  [ModuleExport(typeof(DeliveryModule))]
    public class DeliveryModule : IModule
    {
        [Import(AllowRecomposition=false)]
        public IRegionManager regionManager;

 
        public void Initialize()
        {
            this.regionManager.RegisterViewWithRegion(RegionNames.TabRegion, typeof(Deliveries));
            
        }
    }
Here is the problem:
When I click on GotoDatapool button on deliveries.xaml, NavigationCompleted.result is true. it hits the break point NavigatedTo on datapoolviewmodel.
It has both views in RegionsManager.(I checked in debug mode). but why is not getting activated?
what am I doing wrong? Please help. I saw other samples. I couldn't see what i'm doing wrong. I'm new to prism. so struggling in this bit. 

Developer
Aug 24, 2012 at 3:04 PM
Edited Aug 24, 2012 at 3:05 PM

Hi,

So far I couldn't find anything wrong within the code snippets you provided. Based on your descriptions I created a small sample, where the tab gets activated without problems when navigating to the "DataPoolView" perhaps, you could find it useful to compare any differences with your own implementation. Note that in my case I return false in the IsNavigationTarget method of the DataPoolViewModel, hence a new instance of the view is created each time you navigate to it.

You could find the sample in my SkyDrive account under the name "TabControlRegionSample".

I hope you find this helpful,

Agustin Adami
http://blogs.southworks.net/aadami

Sep 1, 2012 at 2:14 PM

Thanks a lot. sorry. I somehow hadn't seen this reply at all. 

I removed the registration in module and used viewexport on delivery view. it worked. 

thanks again for the effort.

 

I'm now stuck in another problem. I was hoping you could help me with that? 

would be greatful

 

http://compositewpf.codeplex.com/discussions/394045

Kavya