chris
chris

Reputation: 148

Custom menu is not clickable

I am trying to create a 3 horizontal dot menu. My code below sets the 3 dots fine but the menu can't be clicked and doesn't show the menu item with the header "Remove item".

Any ideas why?

<Window.Resources>
        <Style TargetType="{x:Type Menu}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Menu}">
                        <Canvas >
                            <Path Data="M12.5,6.5 C12.5,9.8137085 9.8137085,12.5 6.5,12.5 C3.1862915,12.5 0.5,9.8137085 0.5,6.5 C0.5,3.1862915 3.1862915,0.5 6.5,0.5 C9.8137085,0.5 12.5,3.1862915 12.5,6.5 z M30.5,6.5 C30.5,9.8137085 27.813708,12.5 24.5,12.5 C21.186292,12.5 18.5,9.8137085 18.5,6.5 C18.5,3.1862915 21.186292,0.5 24.5,0.5 C27.813708,0.5 30.5,3.1862915 30.5,6.5 z M48.5,6.5 C48.5,9.8137085 45.813708,12.5 42.5,12.5 C39.186292,12.5 36.5,9.8137085 36.5,6.5 C36.5,3.1862915 39.186292,0.5 42.5,0.5 C45.813708,0.5 48.5,3.1862915 48.5,6.5 z" 
                                    Fill="Black" 
                                    HorizontalAlignment="Left" 
                                    Stretch="Fill" 
                                    Stroke="Black"
                                    VerticalAlignment="Top" 
                                    Height="7" Width="23"/>
                        </Canvas>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
    </Window.Resources>
    <Grid>
        <Menu>
            <MenuItem Header="Remove item" FontSize="12" />
        </Menu>       
    </Grid> 

Upvotes: 0

Views: 75

Answers (1)

mm8
mm8

Reputation: 169400

The ControlTemplate is supposed to include an <ItemsPresenter /> element for the child items to be generated.

So you should add the <ItemsPresenter /> element to your custom template. You may for example use a Grid or some other Panel as the root element of the template and then add both the Canvas and the ItemsPresenter to it.

Upvotes: 1

Related Questions