Context Menu vs Popup

2019-06-17 07:48发布

What is the difference between a ContextMenu class and the Popup class?

1条回答
祖国的老花朵
2楼-- · 2019-06-17 08:46

The MSDN docs do a nice job of displaying the distinction:

The Popup Class:

Represents a pop-up window that has content.

The ContextMenu Class:

Represents a pop-up menu that enables a control to expose functionality that is specific to the context of the control.

So the ContextMenu is a more-specific version of a Popup - it's meant to be bound to a specific control, providing ways to interact with that control. Read further on the MSDN page: the ContextMenu has built-in facilities for displaying itself when you right-click on the associated control, and it is automatically displayed within a Popup.

The Popup class is much more general: it simply defines a barebones window (no default borders or decoration) that can display any arbitrary UIElement on top of other controls (notice that the Popup class is part of the Primitives namespace, meaning it's meant to be part of the composition of other controls, such as the ContextMenu).

查看更多
登录 后发表回答