4

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.

Josh G
  • 14,068
  • 7
  • 62
  • 74
  • Disadvantages would be the complexity. Because I'm only using a single toolbar, the repositioning grip would be unnecessary and the control would have to be retemplated to remove it. – Josh G Jun 29 '09 at 15:58
  • 1
    You don't have to re-template to remove the grip; you only need to set a property. http://stackoverflow.com/questions/1050953/wpf-toolbar-how-to-remove-grip-and-overflow – Joe White Jun 29 '09 at 16:58
  • Yes, you're right. It's the collapse button that I have retemplate to remove. – Josh G Jun 29 '09 at 18:22

3 Answers3

9

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
  • 23,359
  • 7
  • 71
  • 108
4

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.

Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
  • +1. Re-styling controls in non-native containers to look like controls in native containers is rarely worth the effort. – micahtan Jun 29 '09 at 15:26
  • So the ToolBar automatically affects the styling of the buttons. – Josh G Jun 29 '09 at 15:27
  • 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 Jun 29 '09 at 15:51
3

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
  • 30,286
  • 23
  • 113
  • 184