In This Article

ToggleSwitch Class

Represents a toggle switch control.

public class ToggleSwitch : CircularGaugeBase, DUCE.IResource, IAnimatable, IFrameworkInputElement, IInputElement, ISupportInitialize, IHaveResources, IQueryAmbient, ILogicalParent, IVisualParent
Inheritance:
Object DispatcherObject DependencyObject Visual UIElement FrameworkElement GaugeElement GaugeBase CircularGaugeBase Object
Implements:
ILogicalParent IVisualParent

Remarks

For detailed documentation on this control's features and how to use them, please see the Gauge documentation topics.

Constructors

ToggleSwitch()

Initializes a new instance of the ToggleSwitch class.

public ToggleSwitch()

Properties

BallBrush

Gets or sets the brush used to render the ball of the switch. This is a dependency property.

public Brush BallBrush { get; set; }

Property Value

Brush:

The brush used to render the ball of the switch. The default value is DarkGray.

BaseAccentBrush

Gets or sets the brush used to render the accent shape on the base. This is a dependency property.

public Brush BaseAccentBrush { get; set; }

Property Value

Brush:

The brush used to render the accent shape on the base. The default value is Black.

BaseBackground

Gets or sets the brush used to render the base background. This is a dependency property.

public Brush BaseBackground { get; set; }

Property Value

Brush:

The brush used to render the base background. The default value is DarkGray.

FocusBrush

Gets or sets brush used to render the focus indicator. This is a dependency property.

public Brush FocusBrush { get; set; }

Property Value

Brush:

The ToggleSwitch focus brush. The default value is DarkGoldenrod.

FocusExtent

Gets or sets the extent of the focus indicator. This is a dependency property.

public Unit FocusExtent { get; set; }

Property Value

Unit:

The extent of the focus indicator. The default value is 3%.

IsChecked

Gets or sets whether the ToggleSwitch is checked. This is a dependency property.

public bool? IsChecked { get; set; }

Property Value

Nullable<Boolean>:

true if the ToggleSwitch is checked; false if the ToggleSwitch is unchecked; otherwise null. The default value is false.

IsSwitchEffectEnabled

Gets and sets a value indicating whether a special effect should be rendered for the switch. This is a dependency property.

public bool IsSwitchEffectEnabled { get; set; }

Property Value

Boolean:

true if the switch effect is enabled; otherwise, false. The default value is true.

IsThreeState

Gets or sets whether the control supports two or three states. This is a dependency property.

public bool IsThreeState { get; set; }

Property Value

Boolean:

true if the control supports three states; otherwise, false. The default value is false.

RenderedFocused

Gets and sets a value indicating whether the switch should be rendered with a focus indicator. This is a dependency property.

protected bool RenderedFocused { get; set; }

Property Value

Boolean:

true if the switch should be rendered with a focus indicator; otherwise, false. The default value is false.

ShaftBrush

Gets or sets the brush used to render the shaft of the switch. This is a dependency property.

public Brush ShaftBrush { get; set; }

Property Value

Brush:

The brush used to render the shaft of the switch. The default value is Gray.

SwitchInterval

Gets or sets the interval that it takes the switch to travel to a new location. This is a dependency property.

public Duration SwitchInterval { get; set; }

Property Value

Duration:

The interval that it takes the switch to travel to a new location. The default value is 250 milliseconds.

SwitchOffset

Gets or sets the offset of the switch, which is used to move it up and down. This is a dependency property.

protected double SwitchOffset { get; set; }

Property Value

Double:

The offset of the switch. The default value is 0.

SwitchRadiusRatio

Gets or sets the radius of the switch as a ratio of the Radius property. This is a dependency property.

public double SwitchRadiusRatio { get; set; }

Property Value

Double:

The radius of the switch as a ratio of the Radius property. The default value is 0.75.

SwitchType

Gets or sets the type of switch rendered. This is a dependency property.

public ToggleSwitchType SwitchType { get; set; }

Property Value

ToggleSwitchType:

The type of switch rendered. The default value is ToggleSwitchType.Circular.

TipBrush

Gets or sets the brush used to render the tip of the switch. This is a dependency property.

public Brush TipBrush { get; set; }

Property Value

Brush:

The brush used to render the tip of the switch. The default value is Gray.

Methods

OnChecked(RoutedEventArgs)

Raises the Checked event.

protected virtual void OnChecked(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

The RoutedEventArgs instance containing the event data.

OnCreateAutomationPeer()

Creates an appropriate ToggleSwitchAutomationPeer for this control as part of the WPF infrastructure.

protected override AutomationPeer OnCreateAutomationPeer()

Returns

AutomationPeer:

An instance of ToggleSwitchAutomationPeer.

OnIndeterminate(RoutedEventArgs)

Raises the Indeterminate event.

protected virtual void OnIndeterminate(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

The RoutedEventArgs instance containing the event data.

OnMouseDown(MouseButtonEventArgs)

Invoked when an unhandled Mouse.MouseDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.

protected override void OnMouseDown(MouseButtonEventArgs e)
Parameter Type Description
e MouseButtonEventArgs

The MouseButtonEventArgs that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.

OnRender(DrawingContext)

When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.

protected override void OnRender(DrawingContext drawingContext)
Parameter Type Description
drawingContext DrawingContext

The drawing instructions for a specific element. This context is provided to the layout system.

OnToggle()

Called by the OnClick method to implement toggle behavior.

protected virtual void OnToggle()

Remarks

This method toggles the IsChecked property.

OnUnchecked(RoutedEventArgs)

Raises the Unchecked event.

protected virtual void OnUnchecked(RoutedEventArgs e)
Parameter Type Description
e RoutedEventArgs

The RoutedEventArgs instance containing the event data.

RenderToggleSwitch(DrawingContext)

Renders the switch based on various properties.

protected virtual void RenderToggleSwitch(DrawingContext drawingContext)
Parameter Type Description
drawingContext DrawingContext

The drawing context.

UpdateSwitchOffset()

Updates the SwitchOffset, usually with an animation.

protected virtual void UpdateSwitchOffset()

Events

Checked

Occurs when the IsChecked property is changed to true.

public event RoutedEventHandler Checked

Event Type

RoutedEventHandler

Indeterminate

Occurs when the IsChecked property is changed to null.

public event RoutedEventHandler Indeterminate

Event Type

RoutedEventHandler

Unchecked

Occurs when the IsChecked property is changed to false.

public event RoutedEventHandler Unchecked

Event Type

RoutedEventHandler

Fields

BallBrushProperty

Identifies the BallBrush dependency property. This field is read-only.

public static readonly DependencyProperty BallBrushProperty

BaseAccentBrushProperty

Identifies the BaseAccentBrush dependency property. This field is read-only.

public static readonly DependencyProperty BaseAccentBrushProperty

BaseBackgroundProperty

Identifies the BaseBackground dependency property. This field is read-only.

public static readonly DependencyProperty BaseBackgroundProperty

CheckedEvent

Identifies the Checked routed event. This field is read-only.

public static readonly RoutedEvent CheckedEvent

FocusBrushProperty

Identifies the FocusBrush dependency property. This field is read-only.

public static readonly DependencyProperty FocusBrushProperty

FocusExtentProperty

Identifies the FocusExtent dependency property. This field is read-only.

public static readonly DependencyProperty FocusExtentProperty

IndeterminateEvent

Identifies the Checked routed event. This field is read-only.

public static readonly RoutedEvent IndeterminateEvent

IsCheckedProperty

Identifies the IsChecked dependency property. This field is read-only.

public static readonly DependencyProperty IsCheckedProperty

IsSwitchEffectEnabledProperty

Identifies the IsSwitchEffectEnabled dependency property. This field is read-only.

public static readonly DependencyProperty IsSwitchEffectEnabledProperty

IsThreeStateProperty

Identifies the IsThreeState dependency property. This field is read-only.

public static readonly DependencyProperty IsThreeStateProperty

RenderedFocusedProperty

Identifies the RenderedFocused dependency property. This field is read-only.

protected static readonly DependencyProperty RenderedFocusedProperty

ShaftBrushProperty

Identifies the ShaftBrush dependency property. This field is read-only.

public static readonly DependencyProperty ShaftBrushProperty

SwitchIntervalProperty

Identifies the SwitchInterval dependency property. This field is read-only.

public static readonly DependencyProperty SwitchIntervalProperty

SwitchOffsetProperty

Identifies the SwitchOffset dependency property. This field is read-only.

protected static readonly DependencyProperty SwitchOffsetProperty

SwitchRadiusRatioProperty

Identifies the SwitchRadiusRatio dependency property. This field is read-only.

public static readonly DependencyProperty SwitchRadiusRatioProperty

SwitchTypeProperty

Identifies the SwitchType dependency property. This field is read-only.

public static readonly DependencyProperty SwitchTypeProperty

TipBrushProperty

Identifies the TipBrush dependency property. This field is read-only.

public static readonly DependencyProperty TipBrushProperty

UncheckedEvent

Identifies the Checked routed event. This field is read-only.

public static readonly RoutedEvent UncheckedEvent

Inherited Members

Extension Methods