ContextMenu 样式和模板ContextMenu Styles and Templates
03/30/2017
本文内容
本主题描述控件的样式和模板 ContextMenu 。This topic describes the styles and templates for the ContextMenu control. 您可以修改默认值 ControlTemplate ,为控件指定独特的外观。You can modify the default ControlTemplate to give the control a unique appearance. 有关详细信息,请参阅为 控件创建模板。
ContextMenu 部件ContextMenu Parts
ContextMenu控件没有任何命名部分。The ContextMenu control does not have any named parts.
When you create a ControlTemplate for a ContextMenu, your template might contain an ItemsPresenter within a ScrollViewer. (The ItemsPresenter displays each item in the ContextMenu; the ScrollViewer enables scrolling within the control). If the ItemsPresenter is not the direct child of the ScrollViewer, you must give the ItemsPresenter the name, ItemsPresenter.
ContextMenu 状态ContextMenu States
下表列出了控件的可视状态 ContextMenu 。The following table lists the visual states for the ContextMenu control.
VisualState 名称VisualState Name
VisualStateGroup 名称VisualStateGroup Name
描述Description
有效Valid
ValidationStatesValidationStates
The control uses the Validation class and the Validation.HasError attached property is false.
InvalidFocusedInvalidFocused
ValidationStatesValidationStates
The Validation.HasError attached property is true has the control has focus.
InvalidUnfocusedInvalidUnfocused
ValidationStatesValidationStates
The Validation.HasError attached property is true has the control does not have focus.
ContextMenu System.windows.controls.controltemplate> 示例ContextMenu ControlTemplate Example
The following example shows how to define a ControlTemplate for the ContextMenu control.
Value="True" />
Value="True" />
Value="true" />
Value="True" />
Background="{StaticResource MenuPopupBrush}"
BorderThickness="1">
KeyboardNavigation.DirectionalNavigation="Cycle" />
Value="true">
Property="Padding"
Value="0,3,0,3" />
Property="CornerRadius"
Value="4" />
The ControlTemplate uses the following resources.
#FFE8EDF9
#FFC5CBF9
#FF7381F9
#FFE8EDF9
#FFC5CBF9
#FF888888
#FFC5CBF9
#FFDDDDDD
White
#FF7381F9
#FF211AA9
#FF3843C4
#FF211AA9
#FF444444
sc#1, 0.004391443, 0.002428215, 0.242281124
#FFCCCCCC
#FF888888
#FF444444
#FF888888
#FF444444
#FFAAAAAA
#FF888888
Black
#FFC5CBF9
Black
#FFC5CBF9
#FF3843C4
EndPoint="0.5,1"
StartPoint="0.5,0">
Offset="0" />
Offset="0.5" />
Offset="1" />
StartPoint="0,0"
EndPoint="1,0">
Offset="0" />
Offset="0.4" />
Offset="0.6" />
Offset="1" />
另请参阅See also