MenuAction.Checked 属性

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

获取或设置一个值指示是否选中该菜单项。

命名空间:  Microsoft.Windows.Design.Interaction
程序集:  Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)

语法

声明
Public Property Checked As Boolean
public bool Checked { get; set; }
public:
property bool Checked {
    bool get ();
    void set (bool value);
}
member Checked : bool with get, set
function get Checked () : boolean
function set Checked (value : boolean)

属性值

类型:System.Boolean
如果呈现的菜单项应带有一个选中标记,则为 true;否则为 false。默认值为 false。

备注

Checked 属性只有在 Checkable 属性设置为 true 时有效。

示例

下面的代码示例演示如何根据控件的 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 安全性

请参见

参考

MenuAction 类

Microsoft.Windows.Design.Interaction 命名空间

PrimarySelectionContextMenuProvider

MenuGroup

其他资源

演练:创建菜单提供程序