views:

2100

answers:

3

I'm trying to decide whether I should create a simple StackPanel with Buttons on it, or whether I should use the WPF ToolBar class to contain these buttons (I am creating a simple toolbar).

What are the pros and cons to using WPF's built-in ToolBar control?

So far, these are the only advantages I have seen:

  • The ToolBars can collapse when necessary; additional items are available from a context drop down.
  • If the ToolBar is contained within a ToolBarTray, multiple ToolBars can be repositioned relative to each other.

Are the any other benefits to the WPF ToolBar? Neither of these apply to my simple toolbar.

+2  A: 

I would say use the Toolbar, because you never know when the next project will come along and need it. You also never know when this project may need it. I don't think there is any real drawback to using it over a StackPanel and the advantage you didn't mention is you'll have more experiance with a built in control for the next project.

On the other hand, I don't see any harm in doing it with the StackPanel, only that if you need to extend functionallity in the future, you'll have to do some rework.

Nate Bross
+4  A: 

Another very small advantage is that buttons in the ToolBar will be styled correctly, whereas the buttons in the StackPanel will take on their default look. Not insurmountable by any means, but a little annoyance none-the-less.

HTH, Kent

Kent Boogaart
+1. Re-styling controls in non-native containers to look like controls in native containers is rarely worth the effort.
micahtan
So the ToolBar automatically affects the styling of the buttons.
Josh G
Yes, but it's possible for you to apply these styles to your own buttons or checkboxes or whatever. Look at the static members on ToolBar to see what I mean.
Kent Boogaart
+7  A: 

Accessibility might be better with the WPF Toolbar, because it shows itself to Windows UI Automation as a toolbar with toolbar buttons, rather than some random controls. You never know who'll use your software.

OregonGhost
Great answer - this never would have occurred to me.
Joe White