一千萬個為什麽

搜索

禁用Infragistics工具欄按鈕(ButtonTool)

我需要啟用/禁用ButtonTool。

在使用Infragistics之前,我使用了一個具有“Enabled”屬性的ordinaly WinForms ToolbarButton。

我像這樣使用數據綁定:

UndoButtonTool.DataBindings.Clear()
UndoButtonTool.DataBindings.Add("Enabled", memory, "CanUndo")

我現在如何使用infragistics ButtonTool?

UndoButtonTool.DataBindings.Clear()
UndoButtonTool.DataBindings.Add("SharedProps.Enabled", memory, "CanUndo")

不管用...

我已經實現了一個自定義的BindableButtonTool:

Public Class ToolStripBindableButton
  Inherits Infragistics.Win.UltraWinToolbars.ButtonTool
  Implements IBindableComponent

  Private _DataBindings As ControlBindingsCollection
  Private _BindingContext As BindingContext
  Private _Site As System.ComponentModel.ISite

  Public Event DisposedAsStrip As EventHandler Implements IBindableComponent.Disposed

  Sub New(ByVal name As String)
    MyBase.New(name)
  End Sub

  Public ReadOnly Property DataBindings() As ControlBindingsCollection Implements System.Windows.Forms.IBindableComponent.DataBindings
    Get
      If _DataBindings Is Nothing Then
        _DataBindings = New ControlBindingsCollection(Me)
      End If
      Return _DataBindings
    End Get
  End Property

  Public Property BindingContext() As BindingContext Implements System.Windows.Forms.IBindableComponent.BindingContext
    Get
      If _BindingContext Is Nothing Then
        _BindingContext = New BindingContext()
      End If
      Return _BindingContext
    End Get
    Set(ByVal value As BindingContext)
      _BindingContext = value
    End Set
  End Property

  Public Overloads Sub Dispose()
    If _DataBindings IsNot Nothing Then
      _DataBindings.Clear()
      _DataBindings = Nothing
    End If
    _BindingContext = Nothing

    MyBase.Dispose()

    RaiseEvent DisposedAsStrip(Me, EventArgs.Empty)
  End Sub

  Property Site As System.ComponentModel.ISite Implements System.ComponentModel.IComponent.Site
    Get
      Return _Site
    End Get
    Set(ByVal value As System.ComponentModel.ISite)
      _Site = value
    End Set
  End Property

End Class

最佳答案

要啟用/禁用Infragistics ButtonTool,您可以使用以下代碼

myButtonTool.SharedProps.Enabled = True/False

轉載註明原文: 禁用Infragistics工具欄按鈕(ButtonTool)