ContextMenuProvider.UpdateItemStatus 事件
更新:2007 年 11 月
會在功能表項目即將顯示時發生。
命名空間: Microsoft.Windows.Design.Interaction
組件: Microsoft.Windows.Design.Extensibility (在 Microsoft.Windows.Design.Extensibility.dll 中)
語法
Public Event UpdateItemStatus As EventHandler(Of MenuActionEventArgs)
Dim instance As ContextMenuProvider
Dim handler As EventHandler(Of MenuActionEventArgs)
AddHandler instance.UpdateItemStatus, handler
public event EventHandler<MenuActionEventArgs> UpdateItemStatus
public:
event EventHandler<MenuActionEventArgs^>^ UpdateItemStatus {
void add (EventHandler<MenuActionEventArgs^>^ value);
void remove (EventHandler<MenuActionEventArgs^>^ value);
}
JScript 不支援事件。
範例
在下列程式碼範例中,會說明如何處理 UpdateItemStatus 事件,以更新具有來自主要選取之值的 MenuAction 物件。如需詳細資訊,請參閱逐步解說:建立 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