简体   繁体   中英

Prism and AnimatedTabControl

I would love to use this, but cannot for the life of me figure out how to bind items to it.

I would like to see a simple example, something like

Shell.xaml

<Controls:AnimatedTabControl
   x:Name="TestTab"
   SelectedIndex="0"
   VerticalAlignment="Stretch"
   cal:RegionManager.RegionName="{x:Static inf:RegionNames.TestRegion}" 
   Grid.Row="1"  
/>

--

using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;

namespace HelloWorldModule
{
    public class HelloWorldModule : IModule
    {
        private readonly IRegionManager regionManager;
        public HelloWorldModule(IRegionManager regionManager)
        {
            this.regionManager = regionManager;
        }

       public void Initialize()
       {
        regionManager.RegisterViewWithRegion(
            RegionNames.SecondaryRegion, typeof(Views.HelloWorldView));
        regionManager.RegisterViewWithRegion(
            RegionNames.TestRegion, typeof(Views.TestTab));
       }
    }
}

What code is needed to have multiple tabs that animate on change in TestRegion . I cannot seem to figure out how to bind anything to AnimatedTabControl or even a regular tab control...

I think the problem you're facing is that you're using View Discovery when you actually want to use View Injection.

With View Discovery, you register views with a region and, when the region gets displayed, each of the views get dynamically loaded. My guess is that you're registering views with a region after the region has been made visible. This means that your views will never get instantiated as the Region has already been made visible.

View Injection dynamically inserts a view into an already existing region. I think this is what you want to do. Your shell is fine but you'll need to add the following to your Module Initialize() call:

Views.HelloWorldView hello= new Views.HelloWorldView();
regionmanager.Regions[RegionNames.TestRegion].Add(hello);

This should do the trick.

NB: you can show/hide views in a region by calling the Activate/Deactivate method on the IRegion like so:

regionmanager.Regions[RegionNames.TestRegion].Activate(hello);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM