Custom WPF Events
This shows an example of adding a custom WPF event to a control, called ImagingControl.
public delegate void CameraConnectedEventHandler(object sender, CameraConnectedRoutedEventArgs e);
public static readonly RoutedEvent CameraConnectedEvent = System.Windows.EventManager.RegisterRoutedEvent(
"CameraConnected", RoutingStrategy.Bubble, typeof(CameraConnectedEventHandler), typeof(ImagingControl));
public event CameraConnectedEventHandler CameraConnected
{
add { this.AddHandler(CameraConnectedEvent, value); }
remove { this.RemoveHandler(CameraConnectedEvent, value); }
}
public class CameraConnectedRoutedEventArgs : RoutedEventArgs
{
public CameraConnectedRoutedEventArgs(RoutedEvent routedEvent, bool bIsConnected)
{
RoutedEvent = routedEvent;
IsConnected = bIsConnected;
}
public bool IsConnected { get; set; }
}
The event is raised in this line of code:
RaiseEvent(new CameraConnectedRoutedEventArgs(CameraConnectedEvent, m_LineScanCamera.Connected));
Comments
Post a Comment