Share via


MenuAction.Enabled, propriété

Obtient ou définit une valeur indiquant si l'élément d'action de menu est accessible à l'utilisateur.

Espace de noms :  Microsoft.Windows.Design.Interaction
Assembly :  Microsoft.Windows.Design.Interaction (dans Microsoft.Windows.Design.Interaction.dll)

Syntaxe

'Déclaration
Public Property Enabled As Boolean
    Get
    Set
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)

Valeur de propriété

Type : System.Boolean
true si l'élément d'action de menu est accessible à l'utilisateur ; sinon, false.La valeur par défaut est true.

Notes

Lorsque les propriétés Enabled et Visible sont true, le concepteur appelle la méthode Execute sur Command.

Exemples

L'exemple de code suivant indique comment configurer deux éléments MenuAction d'après la valeur de la propriété Background d'un contrôle. Pour plus d'informations, consultez Procédure pas à pas : création d'un fournisseur de menus.

' 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;
    }
}

Sécurité .NET Framework

Voir aussi

Référence

MenuAction Classe

Microsoft.Windows.Design.Interaction, espace de noms

PrimarySelectionContextMenuProvider

MenuGroup

Autres ressources

Procédure pas à pas : création d'un fournisseur de menus