Pregunta

I have a context menu which is displayed when I right clicked on the items, on header and on empty space of the listview. How can I display the context menu on the empty space of the listview but not on the header.

        <ListView.View>
            <GridView AllowsColumnReorder="True" 
                <GridViewColumn Width="100" Header="Company" DisplayMemberBinding="{Binding Company}"  />
                <GridViewColumn Width="100" Header="Depatment"  DisplayMemberBinding="{Binding Department}" />
                <GridViewColumn Width="100" Header="Office" DisplayMemberBinding="{Binding Office}" />
            </GridView>
        </ListView.View>
        <ListView.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Add" Command="{Binding Add}"></MenuItem>
            </ContextMenu>
        </ListView.ContextMenu>
¿Fue útil?

Solución

If you set the value of columnheader context menu to null, ie. ColumnHeaderContextMenu="{x:Null}" it's not gonna work ... But you can hack it like this

<GridView.ColumnHeaderContextMenu>
                    <ContextMenu>
                        <ContextMenu.Template>
                            <ControlTemplate>
                                <Border BorderBrush="Transparent"
                                        Background="Transparent" />
                            </ControlTemplate>
                        </ContextMenu.Template>
                    </ContextMenu>
                </GridView.ColumnHeaderContextMenu>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top