I have a WPF application with a simple tabular region layout as follows:
-----------------------------
| Region 1 | Region 2 |
-----------------------------
| Region 3 | Region 4 |
-----------------------------
I want to offer the ability to register modules and their position based on module/app configuration e.g. Register "Module1" in Region 1 and set its rowspan to 2 so that it overlaps region3 or perhaps register Module1, Module2, Module3 and Module4 in there respective regions, or alternatively register Module1 so that it consumes the entire grid.
My current thinking is to define the four regions in the Shell, load the modules from a XAML module catalog and set the row/column/rowspan/columnspan from the app.config however it would be ideal if there was some way in which I could extend the module catalog so that each module entry could directly specify the grid settings directly (much like attached dependency properties), I could then read these during module initalisation and register the modules in each region as required.
Hope this makes sense if not let me know and I'll try to clarify - I may well be overcomplicating things!
First of all, in the question you are confusing views with modules. A module can be initialized without adding any views at all to your UI, or it may add several. So, assuming that in your case a module will expose exactly one type of view, it would be better to describe the setup as "add View1 in Region1" etc.
To solve your problem, you can use the Grid-based approach in your example like this:
It is then very simple to achieve your goal like this:
var view = container.Resolve(typeOfViewFromAddOnModule);
var uiElement = (UIElement)view; // because that's what it's going to be
Grid.SetColumn(uiElement, X);
Grid.SetRow(uiElement, Y);
Grid.SetColumnSpan(uiElement, Z);
Grid.SetRowSpan(uiElement, W);
var region = // get a reference to your Grid region here
region.Add(view);
You are free to determine the values of X
, Y
, Z
, W
in whatever way you wish (load them from configuration, auto-assign them if they are not present, have the add-on module specify them in the "module initialized" event, etc etc).