How can i inject RibbonController in some region on Shell window?

Oct 15, 2008 at 4:44 PM
Edited Oct 15, 2008 at 4:45 PM
In my Shell.xaml:
.....
        <StackPanel DockPanel.Dock="Top">
            <Grid Name="titleHook" Background="Gainsboro" />
            <Grid Name="ribbonGrid" Background="WhiteSmoke" />
        </StackPanel>
......

In Shell class:

        private RibbonController ribbonController = null;

        public Shell()
        {
            InitializeComponent();
            this.ribbonController = new RibbonController(this.ribbonGrid, this.titleHook, this);
        }

And then all modules works with ribbonController:

        [Dependency]
        public IShell Shell { get; set; }

        public void Initialize()
        {
            Window shell = (Window)Shell;

            IRegion mainRegion = this.regionManager.Regions["MainRegion"];
            Views.OperationListView.OperationListView view = new Views.OperationListView.OperationListView();
            view.ParentWindow = shell; //then module works with this property: ((IShell)this.view.ParentWindow).RibbonController ....
            mainRegion.Add(view);
            mainRegion.Activate(view);
        }

But how to do somethink like this:

        public void Initialize()

        {

            IRegion mainRegion = this.regionManager.Regions["MainRegion"];

            Views.OperationListView.OperationListView view = new Views.OperationListView.OperationListView();

            mainRegion.Add(view)

            mainRegion.Activate(view);


            IRegion mainRegion = this.regionManager.Regions["MenuRegion"];

            Views.OperationListView.OperationMenu menu = new Views.OperationListView. OperationMenu();

            mainRegion.Add(menu);

            mainRegion.Activate(menu);

        }

Thanks


Oct 21, 2008 at 5:54 PM

Hi,

 

If you are using the UnityContainer, what you could do is register the instance of the RibbonController in the container using an interface (i.e.: IRibbonController) and, then, create the views by resolving them in the container, in order to get the RibbonController injected (via constructor or using the Dependency attribute on a property). For example:

 

1- Registering the instance:

IRibbonController ribbonController = new RibbonController(this.ribbonGrid, this.titleHook, this);

myUnityContainer.RegisterInstance<IRibbonController>(ribbonController);

 

2-a) Setting the view to get the RibbonController via constructor injection:

public IRibbonController MyRibbonController { get; set; }

 

public OperationListView(IRibbonController ribbonController)

{

    MyRibbonController = ribbonController;

}

 

2-b) Or, setting the view to get the RibbonController via setter injection:

[Dependency]

public IRibbonController MyRibbonController { get; set; }

 

3- Using the container to create the view and resolve its dependencies:

IRegion mainRegion = this.regionManager.Regions["MainRegion"];

Views.OperationListView.OperationListView view = myUnityContainer.Resolve<Views.OperationListView.OperationListView>();

mainRegion.Add(view)

mainRegion.Activate(view);

 

To get a reference to the Main Window (as shown in the thread How to set .Owner to Shell for a new Window): Application.Current.MainWindow

 

If this is not your scenario, please send more information.

 

Please, let me know if this helps.

 

Ignacio Baumann Fonay

http://blogs.southworks.net/ibaumann/