public class LightSwitch : Control { // Not a complete Silverlight custom control but enough // to demonstrate providing accessibility support via // AutomationPeer and UI Automation private bool _stateOn; public LightSwitch(){} public bool State { get { return this._stateOn; } set { changeState(value); } } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { e.Handled = true; base.OnMouseLeftButtonDown(e); this.Toggle(); } public void Toggle() { changeState(!this._stateOn); } protected override AutomationPeer OnCreateAutomationPeer() { return new LightSwitchAutomationPeer(this); } public void changeState(bool newState) { // notify accessibility that the state changed LightSwitchAutomationPeer ap = FrameworkElementAutomationPeer.FromElement(this) as LightSwitchAutomationPeer; if (ap != null) { ap.RaiseStateChangedEvent(this._stateOn, newState); } // flip light switch state this._stateOn = !this._stateOn; // update visuals this.updateVisuals(this._stateOn); } }