views:

210

answers:

1

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));
    }
}

}

<UserControl x:Class="HelloWorldModule.Views.HelloWorldView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cal="http://www.codeplex.com/CompositeWPF" > <Grid > <TextBlock Text="Hello" Foreground="Green" ></TextBlock> </Grid> </UserControl>

and finally. to where I am STUCK:

What would be the code for the TestRegion to be able to have multiple tabs that do the animation on change? I cannot seem to figure out how to bind anything to AnimatedTabControl or even a regular tab control...

A: 

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);

gadsUK