This project is read-only.

Battleship toolbar

May 3, 2013 at 8:02 PM
Edited May 3, 2013 at 8:05 PM
Would it be possible to get an example of the battleship toolbar implementation? Ideally one that used 2 dockable toolbars that can also be hidden?

I also need to be able to save and restore the locations. I know how to save/get the location and visibility values, just not sure of the right way to pass them to the toolbar from StartViewModel.cs.

I got as far as:
Actions.Add(new ViewActionToolbar())

And I looked at the code and see the 3 dependencyProperties, but am at a lost as to what to do next. I am guessing I need to add the buttons via the SelectedViewProperty, but not sure of the best way to do so.

Do the other themes support the toolbar (even if they show it differently)? I don't need it, but was curious.


May 16, 2013 at 11:06 PM
The way the battleship toolbars work is modeled after the Internet Explorer toolbar. So the toolbars are not as such dockable or movable. They just always stay at the top of the form.

Whether a toolbar is visible or not depends on whether there are items in it. If you have view actions in your view model, then those should be visible in the toolbar. (Same for the main actions from the start view model). You can of course use the CanExecute stuff in the actions to determine whether they are available or not, and you can also completely remove the toolbar items by simply removing them from the actions collection. When no actions are left, the toolbar is invisible.

The default template should create actions that are visible in the toolbar, btw.

May 16, 2013 at 11:44 PM

I can live with the toolbar stuck at the top (at least for now.)

What might be helpful is a simple example that had some menu items and a toolbar.

In my case, my call to create a menu option is:

Actions.Add(new ViewAction("Customers", execute: (a, o) => Controller.Action("Customer", "List"), category: "Customer")
Significance = ViewActionSignificance.AboveNormal,
ActionView = Controller.LoadView(StandardViews.LargeText03),
ActionViewModel = new CustomerListViewModel()

What do I do different to get the same option to also appear in a toolbar? Since I don't see any specific statement that forces this to be a menu, I don't know what I would change to have it go into a toolbar.

I tried to use the following to create a toolbar, but this didn't work:
Actions.Add(new ViewActionToolbar());

I then tried:
ViewActionToolbar foo = new ViewActionToolbar();

But then couldn't figure out what to do with foo (it doesn't seem to have an items, buttons, Add(), viewxxx, or other method/property to which I could add buttons.

I am sure it's really simple, I just seem to be missing it.
May 18, 2013 at 12:57 PM
The way this works is actually pretty straightforward: In the Battleship theme, all view actions of the StartViewModel that have their Significance property set to Highest, will (by default) show in the toolbar. So if you define your view action like this inside the StartViewModel, it will show up as a toolbar item in addition to being in the menu:
Actions.Add(new ViewAction("Customers", execute: (a, o) => Controller.Action("Customer", "List"), category: "Customer") 
    Significance = ViewActionSignificance.Highest,
Note: This is only the default behavior and it can be changed in the Shell style in the battleship theme. But that is probably not needed in most scenarios.

Then of course there are view actions defined by individual views. All view actions defined in individual view models are always shown in toolbars in the Battleship theme.

May 24, 2013 at 10:26 PM
FYI: Based on this discussion I felt inspired to add a tweak to the system. The default now is to show all actions from the start view model with Significance = Highest, and all view actions from the currently open view(model) where the significance is below normal or higher (so by default, lowest significance actions will not be shown in the toolbar, even for the local view, but of course they still show up in the menu). All of this can be tweaked by setting properties in ViewActionToolbar object in the Shell style of course.