MenuAction.Enabled 属性
[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]
获取或设置一个值指示是否用户可以使用菜单操作项。
命名空间: Microsoft.Windows.Design.Interaction
程序集: Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)
语法
声明
Public Property Enabled As Boolean
public bool Enabled { get; set; }
public:
property bool Enabled {
bool get ();
void set (bool value);
}
member Enabled : bool with get, set
function get Enabled () : boolean
function set Enabled (value : boolean)
属性值
类型:System.Boolean
如果用户可以使用该菜单操作项,则为 true;否则为 false。默认值为 true。
备注
当 Enabled 和 Visible 属性为 true 时,设计器对 Command 调用 Execute 方法。
示例
下面的代码示例演示如何根据控件的 Background 属性的值来设置两个 MenuAction 项。 有关更多信息,请参见演练:创建菜单提供程序。
' The following method handles the UpdateItemStatus event.
' It sets the MenuAction states according to the state
' of the control's Background property. This method is
' called before the context menu is shown.
Sub CustomContextMenuProvider_UpdateItemStatus( _
ByVal sender As Object, _
ByVal e As MenuActionEventArgs)
' Turn everything on, and then based on the value
' of the BackgroundProperty, selectively turn some off.
clearBackgroundMenuAction.Checked = False
clearBackgroundMenuAction.Enabled = True
setBackgroundToBlueMenuAction.Checked = False
setBackgroundToBlueMenuAction.Enabled = True
' Get a ModelItem which represents the selected control.
Dim selectedControl As ModelItem = _
e.Selection.PrimarySelection
' Get the value of the Background property from the ModelItem.
Dim backgroundProperty As ModelProperty = _
selectedControl.Properties("Background")
' Set the MenuAction items appropriately.
If Not backgroundProperty.IsSet Then
clearBackgroundMenuAction.Checked = True
clearBackgroundMenuAction.Enabled = False
ElseIf backgroundProperty.ComputedValue.Equals(Brushes.Blue) Then
setBackgroundToBlueMenuAction.Checked = True
setBackgroundToBlueMenuAction.Enabled = False
End If
End Sub
// The following method handles the UpdateItemStatus event.
// It sets the MenuAction states according to the state
// of the control's Background property. This method is
// called before the context menu is shown.
void CustomContextMenuProvider_UpdateItemStatus(
object sender,
MenuActionEventArgs e)
{
// Turn everything on, and then based on the value
// of the BackgroundProperty, selectively turn some off.
clearBackgroundMenuAction.Checked = false;
clearBackgroundMenuAction.Enabled = true;
setBackgroundToBlueMenuAction.Checked = false;
setBackgroundToBlueMenuAction.Enabled = true;
// Get a ModelItem which represents the selected control.
ModelItem selectedControl = e.Selection.PrimarySelection;
// Get the value of the Background property from the ModelItem.
ModelProperty backgroundProperty =
selectedControl.Properties["Background"];
// Set the MenuAction items appropriately.
if (!backgroundProperty.IsSet)
{
clearBackgroundMenuAction.Checked = true;
clearBackgroundMenuAction.Enabled = false;
}
else if (backgroundProperty.ComputedValue == Brushes.Blue)
{
setBackgroundToBlueMenuAction.Checked = true;
setBackgroundToBlueMenuAction.Enabled = false;
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.Windows.Design.Interaction 命名空间
PrimarySelectionContextMenuProvider