Hi, I am working with a screen with an infinite vertical height (the entire contents of the xaml is encased in Scrollviewer)
When the screen first opens, there are two default panels, and the user has the option to add as many panels as he/she wants.
Everytime they open a new panel, I would like it to dock underneath any existing panels (so as the user adds panels, the screen fills up vertically, the scrollviewer becomes longer etc.)
This code works for me if I am trying to add a panel to the right side of the screen in MainViewModel.cs:
public void OpenPositionSummary()
{
var view = _container.Resolve<PositionSummaryView>();
view.DataContext = _container.Resolve<PositionSummaryViewModel>();
var region = RegionManager.Regions["DockedRight"];
region.Add(view); //add the view
region.Activate(view); //active the view
}
But if I change the code to
var region = RegionManager.Regions["DockedBottom"];
I get an error.
How can I make it so that my viewmodel always adds panels to the bottom of whatever is currently on the screen?
Thanks
Hi Christian,
Let me know if you have any further questions on this matter.
You can use the RegionManager.SetRegionName static method to create them. The first parameter is a DependencyObject which corresponds to your target panel. The second parameter is the name you want to use for the region. Just be aware that your region names need to be unique so you can't use DockedBottom for all of those panels.
http://msdn.microsoft.com/en-us/library/microsoft.practices.prism.regions.regionmanager.setregionname(v=pandp.50).aspx
Well, while we're here :)
Is there a way to programatticaly create a panel region in the view/viewModel
To use the example above, if I define the region DockedBottom in the xaml, the first time I open that particular viewmodel, it shows up in the bottom of the screen.
If I want to open ANOTHER instance of that same screen, it opens a new tab in the same location as the first instance. As previously described, I always want new instances to appear UNDERNEATH open instances (as in, you have to scroll down to see the second instance). So is there some code you can provide to register and define new regions on the fly?
Hello Christian,
Not a problem. As you've found out, normally regions are described in the XAML directly using the RegionManager.RegionName attached property so if a region doesn't exist it is usually because either the region hasn't been setup in XAML or the control that was used for the region no longer exists. (It may have existed at application start but somewhere down the line it was removed, which removes the region as well)
I'm glad you were able to resolve your issue. Let me know if you have any further questions on this matter.
I have found the solution. This is preexisting code (which is why I didn't know this). So there is an enum that has the dock controls listed, and I was using that enum to declare the locations of my panels.. however upon searching for the actual strings they correspond to, I see that the dock locations are explicitly defined in the mainviewmodel.xaml file. There was no "dockbottom" there, hence the error.
Thanks for looking into this for me.