0
votes

Is there a way to sort the views that get added to a ItemsControl region? The views being added are registered with the container and added to the region in each unique module.

Some pseudo code...

Shell:

<Window>  
   <ItemsControl Prism:RegionManager.Region="ItemsRegion"/>  
</Window>

Modules: This is the initialization code in the modules.

protected override void RegisterViewsAndServices()
{
    CommonContainerLifetimeManager.Register<IView, ItemView1>();
    Container.RegisterType<IViewModel, ItemViewModel1>("ItemViewModel1");
}

public override void AdditionalInitialization()
{
    var itemView1 = Container.Resolve<ItemView1>();
    RegionManager.Regions["ItemsRegion"].Add(itemView1);
}

With this approach it is showing the added views in the shell's itemscontrol in the order the modules are loaded. Based on the role of the logged on user different modules are loaded. Is there a way, without having to add a collection inbetween, to sort the itemscontrol.items on a property of the view's viewmodel for example? Is there a way to force the modules to be loaded in a certain order? I am currently using a module catalog.

Thanks

Andy

1

1 Answers

0
votes

So I found the answer to this question... At least I found the answer in Prism v4.

You add a ViewSortHint class attribute to the View's code behind. Prism will find this attribute and sort the views based upon the string you enter in the ViewSortHint parameter.

[ViewSortHint("01")]
public partial class SortedButton : UserControl
{
    public SortedButton()
    {
        InitializeComponent();
    }
}

Hope this helps someone...

Andy