Composite view navigation in PRISM - c#

I've searched online and was unable to find a specific answer to this question so I thought I'd asked. Sorry if I've missed the answer else where.
I work in an application that uses mvvm / prism framework and I'm wondering it it is possible to navigate to a view and then open a specific composite region within it allowing me to reach an end state that would normally taking clicking through a tab control.
Is this possible to do but only when I press a specific button rather than it be the default view navigation.
If so would I do with on initial navigation, or pass a parameter to the new view that says then navigate to the composite views.
Any help would be appreciated.

No. Regions are not controls. You can define a region in a control, say content control, and define what view will be associated with the region. Whenever the control become visible in the visual tree, the regions(the associated view) in the control will be visible.

Related

How do i add another components on the MainWindow?

Struggling, I need a button to open up a window but below the MainWindow in C#. Like in a website you can open other pages but the master page layout doesn't change only the page you are viewing shows differently.
I need similar thing. I have components (tools i added from toolbox) on my MainWindow.xaml so for example if i click on a button i named new student, a tabbed-window where i can capture student details must appear but it must not be a separate windows it must appear within the mainwindow and seem like a one thing. Forgive for my English. I hope someone will understand me though, thanks in advance. I want to have components/functionality according a specific button click but constant Mainwindow, the one with "File" "Edit" "View" "Help".
There are a couple different solutions to you problem, but Visual Studio doesn't quite have something like the Master View option through ASP .NET with webforms.
Option One
Using TabControl. This option is the easiest solution to your problem. The GUI in Visual studio has support for adding components to each tab, which nothing else has. This is the closest component to something like multi-panels in Java, but it will still create the Tabs, which may not be what you are looking for.
Option Two
Using multiple Panels over one another. With this option, you can add multiple panels to your main window and layer each panel over one another. You can add a button or other control which will hide each panel and all of its contents. This is a great solution if you don't want tabs, but it can be frustrating to create in Visual Studio since you must move each panel away from another in order to add/remove/adjust the components on the underlying panel.
Of course there are still a few more controls you can use to produce the results you are looking for, but these are probably the most applicable solutions to your problem.

Force visual tree creation with Prism

I have a TabControl containing Prism regions. I want to trigger some kind of notification (e.g. flashing the tab header) for certain events, and I want to trigger this notification from the components in the Prism regions.
Once the tab containing such a component was open once, this works nicely using VisualTreeUtil.GetParent() and going up until I find my TabControl and can modify it to indicate the notification.
But the problem is that this doesn't work until the tab is opened by the user because VisualTreeUtil.GetParent() returns null; obviously because Prism doesn't hook up the visual tree until then.
Calling UpdateLayout() on the TabItem containing the region doesn't help. I don't want to open the TabItems programmatically, because this would confuse the user.
Is there anything I can do short of implementing a kind of region registry (which would be rather ugly and harder to maintain)?
If you want to look at code, I wrote a minimal solution to demonstrate the issue. The Print Structure button tries to go up the visual tree from the (initially unrendered invisible) hello TextBlock on the second tab. Before you switch to the tab it prints only the TextBlock, afterwards you get to the root of the visual tree. This is what I want to accomplish without switching to the tab.
Adding comment as answer:
This probably isn't exactly the answer you are looking for, but it seems like you're taking a very procedural approach.
Have you considered using an MVVM approach? Each TabItem in the TabControl can have a HeaderTemplate. In the template you can bind to a property in the ViewModel that causes the tab to flash or change appearance
Hm.. IIRC Prism regions are just a configured ContentControl/ContentPresenter. Once they are ready to work, all the bindings and datamodels should be in place, but the trees are left not created because they are invisible. If so, you should be able to call ApplyTemplate() on them to force it. I do not remember, however, if the Prism assigns the contenttemplates/datacontexts upon init, or upon demand - the latter may cause calling ApplyTemplate useless.

What is the good way to interface Ribbon control with Caliburn Micro?

I'm using Caliburn Micro for my project, and I decided to use Fluent Ribbon as part of the UI. My ShellView is really simple, and it's laid out like this:
Ribbon Control with 4 tabs.
ActiveItem.
The Active item is dynamically changed depending on the Ribbon's selected tab.
Question:
What is the proper way to use Ribbon control as a second view for my currently active ViewModel (ActiveItem), while maintaining modularity and all the goodies which come inherit with CM itself? Also, what would it take to "share" my Ribbon control among my ViewModels?
Details:
My ShellViewModel is of type "Conductor.Collection.OneActive", and it changes the ActiveItem to specific ViewModel I associate with selected tab (when event is fired).
My Ribbon is defined in XAML like this:
<ContentControl x:Name="RibbonBar" Micro:View.Model="{Binding ActiveItem}" Micro:View.Context="Ribbon" />
As it shows, Ribbon control is bound to currently active item as it's context view. That actually works for one view, because due to default CMs conventions, where it looks for the contextual views in the sub namespace (e.g. if my path to the view is Views.TasksTabView, it will look for the Context view at Views.TasksTab.Ribbon).
Problem is, when I change the ActiveItem, context view can't be located anymore, due to the different namespace, so It only works for one Tab.
I've also tried writing my own ViewLocator convention but I had no success with it.
Thank you.
Unfortunatelly since there are no answers, I'll answer it myself.
I did manage to write the additional ViewLocator logic to locate my Ribbon, but that created some problems (It seems that binding in CM only works once, so after Ribbon being located and bound to the VM, additional context view changes do nothing. There were some hard to find bugs as well).
I've taken a different approach then. I've separated Ribbon to it's own ViewModel, and composited it to the shell with rest of the modules. It uses EventAggregator and I also Inject it where neccessary. Not approach I was hoping for, but it works for now.
If anyone posts better answer, I'll definitelly accept that one.

Having multiple active instances with PRISM

I have an application in PRISM, C#, and I wonder if I can do the following:
I've a button bar on the bottom of my appliction, which acts as my navigation area. The user can click on button A, and the dashboard of module A will pop up.
The user clicks on an item in the dashboard, and he comes to a details page about the item. He is in the pogress of making some changes, but he receives an email during this process.
He opens module B and makes a new item in module B.
--> There are 2 instances open at that moment, the details page of module A, and the add page of module B. I want the user to also visualy pick up on this, because there will be a "1" above the button for module A.
The question is, (how) can I do this with PRISM.
tl;dr; Does PRISM support multiple instanciated views? (it's the "managing" of open views, so you can chose which view to have open.)
I tried googling this, but I couldn't find anything related to it (probably because I'm not sure of how to call this, so I can't search on it :/)
Any info is much appreciated, thanks for your time.
Here's a very short intro on how this works out in Prism, including links to an unbelievably helpful section of MSDN:
Prism has regions, which is an abstraction for controls that can host one or more other controls (your views). Each region can have any number of views added to it, and at most one view in each region is active. The manner in which views (including what it means to be the active view) are displayed is dependent on the region adapter, which is an object created automatically by Prism based on what type of control hosts each region.
Adding to Jon's post.
You might want to use TabControl. If you put PRISM's region into TABCOntrol - you will be able to see all instances as tabs.
You can see decent sample with some XAML on how to close tabs here:
Menu service in Prism application CAL
So, on "inside" - PRISM will have either singleton views/viewmodels if you Export them with MEF by default. If you export those parts as NonShared - PRISM will keep multiple versions of same view inside container (MEF or Unity). However, with buttons - you won't get specific instance.
So, use TabControl as container like this:
Menu service in Prism application CAL
Or you can write your own region adapter and track instances in there.

Tree View of a Data Grid

I am trying to implement some tree like that in ASP.NET: alt text http://i.msdn.microsoft.com/w6ws38fw.vbVenusSiteNavigation_TreeView1(en-us,VS.100).gif
However, this is a TreeView component in the Navigation Tab. I want a DataGrid in a tree view which isn't navigation. Is there a ready FREE component out there?? If not, what is the right component to start with to build such a tree component???
I'm not in a hurry, it will be better for me if I can build my own, but I want to know the component to start with?is it the DataGrid?
Don't get hung up on the fact that it appears in the Navigation tab in the Toolbox - there's nothing to stop you using the <asp:treeview> to represent another hierarchical structure. Have a look at the Treeview Quickstart tutorial which covers using it for data as well as navigation.

Categories

Resources