ToggleSwitch Class
Represents a switch that allows users to toggle the state of an item.
[TemplatePart(Name = "PART_SwitchKnob", Type = typeof(Grid))]
[TemplatePart(Name = "PART_SwitchKnobIndeterminate", Type = typeof(ElementChrome))]
[TemplatePart(Name = "PART_SwitchKnobOff", Type = typeof(ElementChrome))]
[TemplatePart(Name = "PART_SwitchKnobOn", Type = typeof(ElementChrome))]
[TemplatePart(Name = "PART_SwitchKnobShadow", Type = typeof(ShadowChrome))]
[TemplatePart(Name = "PART_KnobTranslateTransform", Type = typeof(TranslateTransform))]
[TemplatePart(Name = "PART_SwitchTrack", Type = typeof(FrameworkElement))]
[TemplatePart(Name = "PART_Thumb", Type = typeof(Thumb))]
public class ToggleSwitch : ToggleButton, IOrientedElement
- Inheritance:
- object Visual UIElement FrameworkElement Control ContentControl ButtonBase ToggleButton object
- Implements:
- IOrientedElement
Constructors
ToggleSwitch()
Initializes an instance of the class.
public ToggleSwitch()
Properties
ContentPlacement
Gets or sets the placement of OnContent, OffContent, and IndeterminateContent.
public ToggleSwitchContentPlacement ContentPlacement { get; set; }
Property Value
- ToggleSwitchContentPlacement:
One of the ToggleSwitchContentPlacement values which indicate the placement of content. The default value is Near.
FarContentMargin
Gets or sets the margin applied to content displayed on the far side of the switch.
public Thickness FarContentMargin { get; set; }
Property Value
- Thickness:
The margin for far side content.
IndeterminateContent
Gets or sets the content for when the switch is "indeterminate".
public object IndeterminateContent { get; set; }
Property Value
- object:
An object that contains the "indeterminate" content.
IndeterminateContentTemplate
Gets or sets the template used to display the IndeterminateContent.
public DataTemplate IndeterminateContentTemplate { get; set; }
Property Value
- DataTemplate:
A DataTemplate used to display the IndeterminateContent.
IndeterminateContentTemplateSelector
Gets or sets the DataTemplateSelector to use for the IndeterminateContent.
public DataTemplateSelector IndeterminateContentTemplateSelector { get; set; }
Property Value
- DataTemplateSelector:
The DataTemplateSelector to use for the IndeterminateContent.
IndeterminateKnobBackground
Gets or sets the brush used for the background of the knob element when the switch is "indeterminate".
public Brush IndeterminateKnobBackground { get; set; }
Property Value
IndeterminateKnobBorderBrush
Gets or sets the brush used for the border of the knob element when the switch is "indeterminate".
public Brush IndeterminateKnobBorderBrush { get; set; }
Property Value
IndeterminateTrackBackground
Gets or sets the brush used for the background of the track element when the switch is "indeterminate".
public Brush IndeterminateTrackBackground { get; set; }
Property Value
IndeterminateTrackBorderBrush
Gets or sets the brush used for the border of the track element when the switch is "indeterminate".
public Brush IndeterminateTrackBorderBrush { get; set; }
Property Value
IsAnimationEnabled
Gets or sets whether animations are enabled for an element, when supported.
public bool IsAnimationEnabled { get; set; }
Property Value
- bool:
true
if animations are enabled; otherwise,false
. The default value istrue
.
IsKnobShadowEnabled
Gets or sets whether the shadow is enabled for the knob element.
public bool IsKnobShadowEnabled { get; set; }
Property Value
- bool:
true
if the shadow is enabled; otherwise,false
. The default value isfalse
.
Remarks
Set this property to false
to prevent the shadow from rendering.
KnobAscent
Gets or sets the size of the knob element on the perpendicular axis (i.e., height when horizontal, width when vertical).
public double KnobAscent { get; set; }
Property Value
- double:
The size of the knob element on the perpendicular axis. The default value is
12
.
Remarks
The largest possible value assigned to this property should also be assigned to MaxKnobAscent.
See Also
KnobBorderThickness
Gets or sets the thickness of the knob element border.
public Thickness KnobBorderThickness { get; set; }
Property Value
KnobCornerRadius
Gets or sets the corner radius of the knob element.
public CornerRadius KnobCornerRadius { get; set; }
Property Value
- CornerRadius:
A CornerRadius for the knob element.
KnobExtent
Gets or sets the size of the knob element on the primary axis (i.e., width when horizontal, height when vertical).
public double KnobExtent { get; set; }
Property Value
- double:
The size of the knob element on the primary axis. The default value is
12
.
Remarks
The largest possible value assigned to this property should also be assigned to MaxKnobExtent.
See Also
KnobMargin
Gets or sets the margin applied to knob element.
public Thickness KnobMargin { get; set; }
Property Value
KnobOpacity
Gets or sets the opacity of the knob element.
public double KnobOpacity { get; set; }
Property Value
- double:
The opacity of the element, a value from
0
to1
. The default value is1
.
KnobShadowDirection
Gets or sets the direction of the shadow for the knob element, in degrees, where 270
is down, 315
is lower-right, etc.
public double KnobShadowDirection { get; set; }
Property Value
- double:
The direction of the shadow, in degrees. The default value is
270
, meaning down.
KnobShadowElevation
Gets or sets the elevation of the shadow for the knob element, a value from 0
to 24
.
public int KnobShadowElevation { get; set; }
Property Value
- int:
The elevation of the shadow, a value from
0
to24
. The default value is0
.
Remarks
Higher elevations render larger shadows. 0
doesn't render a shadow.
The IsKnobShadowEnabled property must be set to true
for the shadow to render.
KnobShadowOpacity
Gets or sets the opacity of the shadow for the knob element.
public double KnobShadowOpacity { get; set; }
Property Value
- double:
The opacity of the shadow, a value from
0
to1
. The default value is0.3
.
MaxKnobAscent
Gets or sets the maximum value which will be assigned to the KnobAscent property.
public double MaxKnobAscent { get; set; }
Property Value
Remarks
Assigning a value to this property is only necessary if the value of KnobAscent increases through user interaction (e.g., the ascent increases on mouse over) so that space is properly reserved in the layout to accommodate the maximum size.
See Also
MaxKnobExtent
Gets or sets the maximum value which will be assigned to the KnobExtent property.
public double MaxKnobExtent { get; set; }
Property Value
Remarks
Assigning a value to this property is only necessary if the value of KnobExtent increases through user interaction (e.g., the extent increases on mouse over) so that space is properly reserved in the layout to accommodate the maximum size.
See Also
NearContentMargin
Gets or sets the margin applied to content displayed on the near side of the switch.
public Thickness NearContentMargin { get; set; }
Property Value
- Thickness:
The margin for near side content.
OffContent
Gets or sets the content for when the switch is "off".
public object OffContent { get; set; }
Property Value
- object:
An object that contains the "on" content. The default value is
null
.
OffContentTemplate
Gets or sets the template used to display the OffContent
public DataTemplate OffContentTemplate { get; set; }
Property Value
- DataTemplate:
A DataTemplate used to display the OffContent.
OffContentTemplateSelector
Gets or sets the DataTemplateSelector to use for the OffContent.
public DataTemplateSelector OffContentTemplateSelector { get; set; }
Property Value
- DataTemplateSelector:
The DataTemplateSelector to use for the OffContent.
OffKnobBackground
Gets or sets the brush used for the background of the knob element when the switch is "off".
public Brush OffKnobBackground { get; set; }
Property Value
OffKnobBorderBrush
Gets or sets the brush used for the border of the knob element when the switch is "off".
public Brush OffKnobBorderBrush { get; set; }
Property Value
OffTrackBackground
Gets or sets the brush used for the background of the track element when the switch is "off".
public Brush OffTrackBackground { get; set; }
Property Value
OffTrackBorderBrush
Gets or sets the brush used for the border of the track element when the switch is "off".
public Brush OffTrackBorderBrush { get; set; }
Property Value
OnContent
Gets or sets the content for when the switch is "on".
public object OnContent { get; set; }
Property Value
- object:
An object that contains the "on" content.
OnContentTemplate
Gets or sets the template used to display the OnContent.
public DataTemplate OnContentTemplate { get; set; }
Property Value
- DataTemplate:
A DataTemplate used to display the OnContent.
OnContentTemplateSelector
Gets or sets the DataTemplateSelector to use for the OnContent.
public DataTemplateSelector OnContentTemplateSelector { get; set; }
Property Value
- DataTemplateSelector:
The DataTemplateSelector to use for the OnContent.
OnKnobBackground
Gets or sets the brush used for the background of the knob element when the switch is "on".
public Brush OnKnobBackground { get; set; }
Property Value
OnKnobBorderBrush
Gets or sets the brush used for the border of the knob element when the switch is "on".
public Brush OnKnobBorderBrush { get; set; }
Property Value
OnTrackBackground
Gets or sets the brush used for the background of the track element when the switch is "on".
public Brush OnTrackBackground { get; set; }
Property Value
OnTrackBorderBrush
Gets or sets the brush used for the border of the track element when the switch is "on".
public Brush OnTrackBorderBrush { get; set; }
Property Value
Orientation
Gets or sets the orientation of the control.
public Orientation Orientation { get; set; }
Property Value
- Orientation:
One of the Orientation values. The default value is Horizontal.
TrackAscent
Gets or sets the size of the track element on the perpendicular axis (i.e., height when horizontal, width when vertical).
public double TrackAscent { get; set; }
Property Value
- double:
The size of the track element on the perpendicular axis. The default value is
20
.
TrackBorderThickness
Gets or sets the thickness of the track element border.
public Thickness TrackBorderThickness { get; set; }
Property Value
TrackContentMargin
Gets or sets the margin applied to content displayed on the track.
public Thickness TrackContentMargin { get; set; }
Property Value
- Thickness:
The margin for track content.
TrackCornerRadius
Gets or sets the corner radius of the track element.
public CornerRadius TrackCornerRadius { get; set; }
Property Value
- CornerRadius:
A CornerRadius for the track element.
TrackExtent
Gets or sets the size of the track element on the primary axis (i.e., width when horizontal, height when vertical).
public double TrackExtent { get; set; }
Property Value
- double:
The size of the track element on the primary axis. The default value is
40
.
TrackOpacity
Gets or sets the opacity of the track element.
public double TrackOpacity { get; set; }
Property Value
- double:
The opacity of the element, a value from
0
to1
. The default value is1
.
Methods
OnApplyTemplate()
Invoked whenever application code or internal processes call ApplyTemplate
.
public override void OnApplyTemplate()
OnPropertyChanged(DependencyPropertyChangedEventArgs)
Called when the value of a System.Windows.DependencyProperty changes.
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | DependencyPropertyChangedEventArgs | An System.Windows.DependencyPropertyChangedEventArgs which defines data for the event. |
Fields
ContentPlacementProperty
Identifies the ContentPlacement dependency property.
public static readonly DependencyProperty ContentPlacementProperty
FarContentMarginProperty
Identifies the FarContentMargin dependency property.
public static readonly DependencyProperty FarContentMarginProperty
IndeterminateContentProperty
Identifies the IndeterminateContent dependency property.
public static readonly DependencyProperty IndeterminateContentProperty
IndeterminateContentTemplateProperty
Identifies the IndeterminateContentTemplate dependency property.
public static readonly DependencyProperty IndeterminateContentTemplateProperty
IndeterminateContentTemplateSelectorProperty
Identifies the IndeterminateContentTemplateSelector dependency property.
public static readonly DependencyProperty IndeterminateContentTemplateSelectorProperty
IndeterminateKnobBackgroundProperty
Identifies the IndeterminateKnobBackground dependency property.
public static readonly DependencyProperty IndeterminateKnobBackgroundProperty
IndeterminateKnobBorderBrushProperty
Identifies the IndeterminateKnobBorderBrush dependency property.
public static readonly DependencyProperty IndeterminateKnobBorderBrushProperty
IndeterminateTrackBackgroundProperty
Identifies the IndeterminateTrackBackground dependency property.
public static readonly DependencyProperty IndeterminateTrackBackgroundProperty
IndeterminateTrackBorderBrushProperty
Identifies the IndeterminateTrackBorderBrush dependency property.
public static readonly DependencyProperty IndeterminateTrackBorderBrushProperty
IsAnimationEnabledProperty
Identifies the IsAnimationEnabled dependency property.
public static readonly DependencyProperty IsAnimationEnabledProperty
IsKnobShadowEnabledProperty
Identifies the IsKnobShadowEnabled dependency property.
public static readonly DependencyProperty IsKnobShadowEnabledProperty
KnobAscentProperty
Identifies the KnobAscent dependency property.
public static readonly DependencyProperty KnobAscentProperty
KnobBorderThicknessProperty
Identifies the KnobBorderThickness dependency property.
public static readonly DependencyProperty KnobBorderThicknessProperty
KnobCornerRadiusProperty
Identifies the KnobCornerRadius dependency property.
public static readonly DependencyProperty KnobCornerRadiusProperty
KnobExtentProperty
Identifies the KnobExtent dependency property.
public static readonly DependencyProperty KnobExtentProperty
KnobMarginProperty
Identifies the KnobMargin dependency property.
public static readonly DependencyProperty KnobMarginProperty
KnobOpacityProperty
Identifies the KnobOpacity dependency property.
public static readonly DependencyProperty KnobOpacityProperty
KnobShadowDirectionProperty
Identifies the KnobShadowDirection dependency property.
public static readonly DependencyProperty KnobShadowDirectionProperty
KnobShadowElevationProperty
Identifies the KnobShadowElevation dependency property.
public static readonly DependencyProperty KnobShadowElevationProperty
KnobShadowOpacityProperty
Identifies the KnobShadowOpacity dependency property.
public static readonly DependencyProperty KnobShadowOpacityProperty
MaxKnobAscentProperty
Identifies the MaxKnobAscent dependency property.
public static readonly DependencyProperty MaxKnobAscentProperty
MaxKnobExtentProperty
Identifies the MaxKnobExtent dependency property.
public static readonly DependencyProperty MaxKnobExtentProperty
NearContentMarginProperty
Identifies the NearContentMargin dependency property.
public static readonly DependencyProperty NearContentMarginProperty
OffContentProperty
Identifies the OffContent dependency property.
public static readonly DependencyProperty OffContentProperty
OffContentTemplateProperty
Identifies the OffContentTemplate dependency property.
public static readonly DependencyProperty OffContentTemplateProperty
OffContentTemplateSelectorProperty
Identifies the OffContentTemplateSelector dependency property.
public static readonly DependencyProperty OffContentTemplateSelectorProperty
OffKnobBackgroundProperty
Identifies the OffKnobBackground dependency property.
public static readonly DependencyProperty OffKnobBackgroundProperty
OffKnobBorderBrushProperty
Identifies the OffKnobBorderBrush dependency property.
public static readonly DependencyProperty OffKnobBorderBrushProperty
OffTrackBackgroundProperty
Identifies the OffTrackBackground dependency property.
public static readonly DependencyProperty OffTrackBackgroundProperty
OffTrackBorderBrushProperty
Identifies the OffTrackBorderBrush dependency property.
public static readonly DependencyProperty OffTrackBorderBrushProperty
OnContentProperty
Identifies the OnContent dependency property.
public static readonly DependencyProperty OnContentProperty
OnContentTemplateProperty
Identifies the OnContentTemplate dependency property.
public static readonly DependencyProperty OnContentTemplateProperty
OnContentTemplateSelectorProperty
Identifies the OnContentTemplateSelector dependency property.
public static readonly DependencyProperty OnContentTemplateSelectorProperty
OnKnobBackgroundProperty
Identifies the OnKnobBackground dependency property.
public static readonly DependencyProperty OnKnobBackgroundProperty
OnKnobBorderBrushProperty
Identifies the OnKnobBorderBrush dependency property.
public static readonly DependencyProperty OnKnobBorderBrushProperty
OnTrackBackgroundProperty
Identifies the OnTrackBackground dependency property.
public static readonly DependencyProperty OnTrackBackgroundProperty
OnTrackBorderBrushProperty
Identifies the OnTrackBorderBrush dependency property.
public static readonly DependencyProperty OnTrackBorderBrushProperty
OrientationProperty
Identifies the Orientation dependency property.
public static readonly DependencyProperty OrientationProperty
TrackAscentProperty
Identifies the TrackAscent dependency property.
public static readonly DependencyProperty TrackAscentProperty
TrackBorderThicknessProperty
Identifies the TrackBorderThickness dependency property.
public static readonly DependencyProperty TrackBorderThicknessProperty
TrackContentMarginProperty
Identifies the TrackContentMargin dependency property.
public static readonly DependencyProperty TrackContentMarginProperty
TrackCornerRadiusProperty
Identifies the TrackCornerRadius dependency property.
public static readonly DependencyProperty TrackCornerRadiusProperty
TrackExtentProperty
Identifies the TrackExtent dependency property.
public static readonly DependencyProperty TrackExtentProperty
TrackOpacityProperty
Identifies the TrackOpacity dependency property.
public static readonly DependencyProperty TrackOpacityProperty