MenuAction.Enabled - свойство
Обновлен: Ноябрь 2007
Возвращает или задает значение, указывающее, доступна ли команда меню пользователю.
Пространство имен: Microsoft.Windows.Design.Interaction
Сборка: Microsoft.Windows.Design.Extensibility (в Microsoft.Windows.Design.Extensibility.dll)
Синтаксис
'Декларация
Public Property Enabled As Boolean
'Применение
Dim instance As MenuAction
Dim value As Boolean
value = instance.Enabled
instance.Enabled = value
public bool Enabled { get; set; }
public:
property bool Enabled {
bool get ();
void set (bool value);
}
public function get Enabled () : boolean
public function set Enabled (value : boolean)
Значение свойства
Тип: System.Boolean
Значение true, если пункт меню доступен для пользователя; в противном случае — значение false. Значение по умолчанию — true.
Заметки
Если свойства Enabled и Visible имеют значение true, то конструктор среды вызывает метод Execute свойства Command.
Примеры
В следующем примере показано, как задать два элемента MenuAction в соответствии со значением свойства 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(Control.BackgroundProperty)
' 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[Control.BackgroundProperty];
// 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;
}
}
Разрешения
- Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в разделе Использование библиотек из не вполне надежного кода.
См. также
Ссылки
Microsoft.Windows.Design.Interaction - пространство имен
PrimarySelectionContextMenuProvider