Sdílet prostřednictvím


MenuAction.Checked – vlastnost

Získá nebo nastaví hodnotu označující, zda je zaškrtnutá položka nabídky.

Obor názvů:  Microsoft.Windows.Design.Interaction
Sestavení:  Microsoft.Windows.Design.Interaction (v Microsoft.Windows.Design.Interaction.dll)

Syntaxe

'Deklarace
Public Property Checked As Boolean
    Get
    Set
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)

Hodnota vlastnosti

Typ: System.Boolean
true Pokud položka nabídky by vykreslen pomocí zaškrtnutí; jinak false.Výchozí hodnota je false.

Poznámky

Checked Vlastnost pouze pokud efekt má vlastnost Checkable je nastavena na true.

Příklady

Následující příklad kódu ukazuje, jak nastavit dvě MenuAction položky podle hodnoty ovládacího prvku Background vlastnost. Další informace naleznete v tématu Walkthrough: Creating a 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;
    }
}

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

MenuAction Třída

Microsoft.Windows.Design.Interaction – obor názvů

PrimarySelectionContextMenuProvider

MenuGroup

Další zdroje

Walkthrough: Creating a MenuAction