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
The placement of OnContent, OffContent, and IndeterminateContent.
public ToggleSwitchContentPlacement ContentPlacement { get; set; }
Property Value
- ToggleSwitchContentPlacement:
The default value is Near.
FarContentMargin
The margin applied to content displayed on the far side of the switch.
IndeterminateContent
The content for when the switch is "indeterminate".
IndeterminateContentTemplate
The template used to display the IndeterminateContent.
IndeterminateContentTemplateSelector
The DataTemplateSelector to use for the IndeterminateContent.
public DataTemplateSelector? IndeterminateContentTemplateSelector { get; set; }
Property Value
IndeterminateKnobBackground
The brush used for the background of the knob element when the switch is "indeterminate".
IndeterminateKnobBorderBrush
The brush used for the border of the knob element when the switch is "indeterminate".
IndeterminateTrackBackground
The brush used for the background of the track element when the switch is "indeterminate".
IndeterminateTrackBorderBrush
The brush used for the border of the track element when the switch is "indeterminate".
IsAnimationEnabled
Indicates whether animations are enabled for an element, when supported.
public bool IsAnimationEnabled { get; set; }
Property Value
- bool:
trueif animations are enabled; otherwise,false. The default value istrue.
IsKnobShadowEnabled
Indicates whether the shadow is enabled for the knob element.
public bool IsKnobShadowEnabled { get; set; }
Property Value
- bool:
trueif the shadow is enabled; otherwise,false. The default value isfalse.
Remarks
Set this property to false to prevent the shadow from rendering.
KnobAscent
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 default value is
12.
Remarks
The largest possible value assigned to this property should also be assigned to MaxKnobAscent.
See Also
KnobBorderThickness
The thickness of the knob element border.
KnobCornerRadius
The corner radius of the knob element.
KnobExtent
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 default value is
12.
Remarks
The largest possible value assigned to this property should also be assigned to MaxKnobExtent.
See Also
KnobMargin
The margin applied to knob element.
KnobOpacity
The opacity of the knob element.
KnobShadowDirection
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 default value is
270, meaning down.
KnobShadowElevation
The elevation of the shadow for the knob element, a value from 0 to 24.
public int KnobShadowElevation { get; set; }
Property Value
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
The opacity of the shadow for the knob element.
MaxKnobAscent
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
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
The margin applied to content displayed on the near side of the switch.
OffContent
The content for when the switch is "off".
OffContentTemplate
The template used to display the OffContent
OffContentTemplateSelector
The DataTemplateSelector to use for the OffContent.
public DataTemplateSelector? OffContentTemplateSelector { get; set; }
Property Value
OffKnobBackground
The brush used for the background of the knob element when the switch is "off".
OffKnobBorderBrush
The brush used for the border of the knob element when the switch is "off".
OffTrackBackground
The brush used for the background of the track element when the switch is "off".
OffTrackBorderBrush
The brush used for the border of the track element when the switch is "off".
OnContent
The content for when the switch is "on".
OnContentTemplate
The template used to display the OnContent.
OnContentTemplateSelector
The DataTemplateSelector to use for the OnContent.
public DataTemplateSelector? OnContentTemplateSelector { get; set; }
Property Value
OnKnobBackground
The brush used for the background of the knob element when the switch is "on".
OnKnobBorderBrush
The brush used for the border of the knob element when the switch is "on".
OnTrackBackground
The brush used for the background of the track element when the switch is "on".
OnTrackBorderBrush
The brush used for the border of the track element when the switch is "on".
Orientation
The orientation of the control.
public Orientation Orientation { get; set; }
Property Value
- Orientation:
The default value is Horizontal.
TrackAscent
The size of the track element on the perpendicular axis (i.e., height when horizontal, width when vertical).
TrackBorderThickness
The thickness of the track element border.
TrackContentMargin
The margin applied to content displayed on the track.
TrackCornerRadius
The corner radius of the track element.
TrackExtent
The size of the track element on the primary axis (i.e., width when horizontal, height when vertical).
TrackOpacity
The opacity of the track element as a value from 0 to 1.
Methods
OnApplyTemplate()
When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate().
public override void OnApplyTemplate()
OnPropertyChanged(DependencyPropertyChangedEventArgs?)
Invoked whenever the effective value of any dependency property on this FrameworkElement has been updated. The specific dependency property that changed is reported in the arguments parameter. Overrides System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs).
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs? e)
| Parameter | Type | Description |
|---|---|---|
| e | DependencyPropertyChangedEventArgs | The event data that describes the property that changed, as well as old and new values. |
Fields
ContentPlacementProperty
Defines the ContentPlacement property.
public static readonly DependencyProperty ContentPlacementProperty
FarContentMarginProperty
Defines the FarContentMargin property.
public static readonly DependencyProperty FarContentMarginProperty
IndeterminateContentProperty
Defines the IndeterminateContent property.
public static readonly DependencyProperty IndeterminateContentProperty
IndeterminateContentTemplateProperty
Defines the IndeterminateContentTemplate property.
public static readonly DependencyProperty IndeterminateContentTemplateProperty
IndeterminateContentTemplateSelectorProperty
Defines the IndeterminateContentTemplateSelector property.
public static readonly DependencyProperty IndeterminateContentTemplateSelectorProperty
IndeterminateKnobBackgroundProperty
Defines the IndeterminateKnobBackground property.
public static readonly DependencyProperty IndeterminateKnobBackgroundProperty
IndeterminateKnobBorderBrushProperty
Defines the IndeterminateKnobBorderBrush property.
public static readonly DependencyProperty IndeterminateKnobBorderBrushProperty
IndeterminateTrackBackgroundProperty
Defines the IndeterminateTrackBackground property.
public static readonly DependencyProperty IndeterminateTrackBackgroundProperty
IndeterminateTrackBorderBrushProperty
Defines the IndeterminateTrackBorderBrush property.
public static readonly DependencyProperty IndeterminateTrackBorderBrushProperty
IsAnimationEnabledProperty
Defines the IsAnimationEnabled property.
public static readonly DependencyProperty IsAnimationEnabledProperty
IsKnobShadowEnabledProperty
Defines the IsKnobShadowEnabled property.
public static readonly DependencyProperty IsKnobShadowEnabledProperty
KnobAscentProperty
Defines the KnobAscent property.
public static readonly DependencyProperty KnobAscentProperty
KnobBorderThicknessProperty
Defines the KnobBorderThickness property.
public static readonly DependencyProperty KnobBorderThicknessProperty
KnobCornerRadiusProperty
Defines the KnobCornerRadius property.
public static readonly DependencyProperty KnobCornerRadiusProperty
KnobExtentProperty
Defines the KnobExtent property.
public static readonly DependencyProperty KnobExtentProperty
KnobMarginProperty
Defines the KnobMargin property.
public static readonly DependencyProperty KnobMarginProperty
KnobOpacityProperty
Defines the KnobOpacity property.
public static readonly DependencyProperty KnobOpacityProperty
KnobShadowDirectionProperty
Defines the KnobShadowDirection property.
public static readonly DependencyProperty KnobShadowDirectionProperty
KnobShadowElevationProperty
Defines the KnobShadowElevation property.
public static readonly DependencyProperty KnobShadowElevationProperty
KnobShadowOpacityProperty
Defines the KnobShadowOpacity property.
public static readonly DependencyProperty KnobShadowOpacityProperty
MaxKnobAscentProperty
Defines the MaxKnobAscent property.
public static readonly DependencyProperty MaxKnobAscentProperty
MaxKnobExtentProperty
Defines the MaxKnobExtent property.
public static readonly DependencyProperty MaxKnobExtentProperty
NearContentMarginProperty
Defines the NearContentMargin property.
public static readonly DependencyProperty NearContentMarginProperty
OffContentProperty
Defines the OffContent property.
public static readonly DependencyProperty OffContentProperty
OffContentTemplateProperty
Defines the OffContentTemplate property.
public static readonly DependencyProperty OffContentTemplateProperty
OffContentTemplateSelectorProperty
Defines the OffContentTemplateSelector property.
public static readonly DependencyProperty OffContentTemplateSelectorProperty
OffKnobBackgroundProperty
Defines the OffKnobBackground property.
public static readonly DependencyProperty OffKnobBackgroundProperty
OffKnobBorderBrushProperty
Defines the OffKnobBorderBrush property.
public static readonly DependencyProperty OffKnobBorderBrushProperty
OffTrackBackgroundProperty
Defines the OffTrackBackground property.
public static readonly DependencyProperty OffTrackBackgroundProperty
OffTrackBorderBrushProperty
Defines the OffTrackBorderBrush property.
public static readonly DependencyProperty OffTrackBorderBrushProperty
OnContentProperty
Defines the OnContent property.
public static readonly DependencyProperty OnContentProperty
OnContentTemplateProperty
Defines the OnContentTemplate property.
public static readonly DependencyProperty OnContentTemplateProperty
OnContentTemplateSelectorProperty
Defines the OnContentTemplateSelector property.
public static readonly DependencyProperty OnContentTemplateSelectorProperty
OnKnobBackgroundProperty
Defines the OnKnobBackground property.
public static readonly DependencyProperty OnKnobBackgroundProperty
OnKnobBorderBrushProperty
Defines the OnKnobBorderBrush property.
public static readonly DependencyProperty OnKnobBorderBrushProperty
OnTrackBackgroundProperty
Defines the OnTrackBackground property.
public static readonly DependencyProperty OnTrackBackgroundProperty
OnTrackBorderBrushProperty
Defines the OnTrackBorderBrush property.
public static readonly DependencyProperty OnTrackBorderBrushProperty
OrientationProperty
Defines the Orientation property.
public static readonly DependencyProperty OrientationProperty
TrackAscentProperty
Defines the TrackAscent property.
public static readonly DependencyProperty TrackAscentProperty
TrackBorderThicknessProperty
Defines the TrackBorderThickness property.
public static readonly DependencyProperty TrackBorderThicknessProperty
TrackContentMarginProperty
Defines the TrackContentMargin property.
public static readonly DependencyProperty TrackContentMarginProperty
TrackCornerRadiusProperty
Defines the TrackCornerRadius property.
public static readonly DependencyProperty TrackCornerRadiusProperty
TrackExtentProperty
Defines the TrackExtent property.
public static readonly DependencyProperty TrackExtentProperty
TrackOpacityProperty
Defines the TrackOpacity property.
public static readonly DependencyProperty TrackOpacityProperty