tags:

views:

490

answers:

1

Having some layout frustrations in WPF- I'm using a ToolBar to house a set of controls, most of which are Buttons and one of which is (going to be) some sort of dropdown menu. In WinForms, the ToolStripDropDownButton was perfect; however, I can't seem to figure out the best way to replicate this behavior in WPF.

Any ideas?

A: 

You could try placing a Menu & MenuItem inside the Toolbar. I've had to use Menu's and MenuItem trees in various parts of the interface (besides classical menus) to get the dropdown menu behavior. You can tweak the control template of the menu to sculpt the look and feel to look however you like and completely abandon the vanilla menu look and feel.

Here's some XAML to show a simple implementation:

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel>
    <ToolBar>
            <Button Content="Button1"></Button>
            <Button Content="Button2"></Button>
            <Menu>
                <MenuItem Header="Menu">
                    <MenuItem Header="MenuItem1"/>
                </MenuItem>
            </Menu>
    </ToolBar>
</StackPanel>

gbc
This was my first approach- it stretched the menu items out to be children of the ToolBar instead of the menu itself. Is this behavior something you've been able to override with a Template / Style?
someweather
Not sure why it's behaving that way for you, I update my answer with a self-contained xaml snippet that seems to work fine here. Let me know if I'm missing something.
gbc
Did the sample posted above work for you?
gbc
That works just fine. I don't remember what the problem was- apologies for the delayed accept, thanks for your response.
someweather
No problem, glad you got it working.
gbc