ToggleSwitch Class

Summary

A control that allows the user to toggle between two states: One represents true; The other represents false.
Namespace
MahApps.Metro.Controls
Interfaces
  • ICommandSource
Base Types
  • HeaderedContentControl
graph BT Type-->Base0["HeaderedContentControl"] Type-.->Interface0["ICommandSource"] Type["ToggleSwitch"] class Type type-node

Syntax

[System.Diagnostics.CodeAnalysis.SuppressMessage("WpfAnalyzers.TemplatePart", "WPF0132:Use PART prefix.", Justification = "<Pending>")]
[ContentProperty(nameof(Content))]
[TemplatePart(Name = nameof(HeaderContentPresenter), Type = typeof(ContentPresenter))]
[TemplatePart(Name = nameof(ContentPresenter), Type = typeof(ContentPresenter))]
[TemplatePart(Name = nameof(OffContentPresenter), Type = typeof(ContentPresenter))]
[TemplatePart(Name = nameof(OnContentPresenter), Type = typeof(ContentPresenter))]
[TemplatePart(Name = nameof(SwitchKnobBounds), Type = typeof(FrameworkElement))]
[TemplatePart(Name = nameof(SwitchKnob), Type = typeof(FrameworkElement))]
[TemplatePart(Name = nameof(KnobTranslateTransform), Type = typeof(TranslateTransform))]
[TemplatePart(Name = nameof(SwitchThumb), Type = typeof(Thumb))]
[TemplateVisualState(GroupName = VisualStates.GroupCommon, Name = VisualStates.StateNormal)]
[TemplateVisualState(GroupName = VisualStates.GroupCommon, Name = VisualStates.StateMouseOver)]
[TemplateVisualState(GroupName = VisualStates.GroupCommon, Name = VisualStates.StatePressed)]
[TemplateVisualState(GroupName = VisualStates.GroupCommon, Name = VisualStates.StateDisabled)]
[TemplateVisualState(GroupName = ContentStatesGroup, Name = OffContentState)]
[TemplateVisualState(GroupName = ContentStatesGroup, Name = OnContentState)]
[TemplateVisualState(GroupName = ToggleStatesGroup, Name = DraggingState)]
[TemplateVisualState(GroupName = ToggleStatesGroup, Name = OffState)]
[TemplateVisualState(GroupName = ToggleStatesGroup, Name = OnState)]
public class ToggleSwitch : HeaderedContentControl, ICommandSource

Attributes

Type Description
SuppressMessageAttribute
ContentProperty
TemplatePart
TemplatePart
TemplatePart
TemplatePart
TemplatePart
TemplatePart
TemplatePart
TemplatePart
TemplateVisualState
TemplateVisualState
TemplateVisualState
TemplateVisualState
TemplateVisualState
TemplateVisualState
TemplateVisualState
TemplateVisualState
TemplateVisualState

Constructors

Name Summary
ToggleSwitch()

Events

Name Type Summary
Toggled RoutedEventHandler
Occurs when "On"/"Off" state changes for this ToggleSwitch.

Fields

Name Constant Value Summary
CommandParameterProperty
Identifies the CommandParameter dependency property.
static
CommandProperty
Identifies the Command dependency property.
static
CommandTargetProperty
Identifies the CommandTarget dependency property.
static
ContentDirectionProperty
Identifies the ContentDirection dependency property.
static
ContentPaddingProperty
Identifies the ContentPadding dependency property.
static
IsOnProperty
Identifies the IsOn dependency property.
static
IsPressedProperty
Identifies the IsPressed dependency property.
static
OffCommandProperty
Identifies the OffCommand dependency property.
static
OffContentProperty
Identifies the OffContent dependency property.
static
OffContentStringFormatProperty
Identifies the OffContentStringFormat dependency property.
static
OffContentTemplateProperty
Identifies the OffContentTemplate dependency property.
static
OffContentTemplateSelectorProperty
Identifies the OffContentTemplateSelector dependency property.
static
OnCommandProperty
Identifies the OnCommand dependency property.
static
OnContentProperty
Identifies the OnContent dependency property.
static
OnContentStringFormatProperty
Identifies the OnContentStringFormat dependency property.
static
OnContentTemplateProperty
Identifies the OnContentTemplate dependency property.
static
OnContentTemplateSelectorProperty
Identifies the OnContentTemplateSelector dependency property.
static

Properties

Name Value Summary
Command ICommand
Gets or sets a command which will be executed when the IsOnProperty changes.
CommandParameter object
Gets or sets the command parameter which will be passed by the Command.
CommandTarget IInputElement
Gets or sets the element on which to raise the specified Command.
ContentDirection FlowDirection
Gets or sets the flow direction of the switch and content.
ContentPadding Thickness
Gets or sets the padding of the inner content.
IsEnabledCore bool
IsOn bool
Gets or sets a value that declares whether the state of the ToggleSwitch is "On".
IsPressed bool
OffCommand ICommand
Gets or sets a command which will be executed when the IsOnProperty changes.
OffContent object
Provides the object content that should be displayed using the OffContentTemplate when this ToggleSwitch has state of "Off".
OffContentStringFormat string
Gets or sets a composite string that specifies how to format the OffContent property if it is displayed as a string.
OffContentTemplate DataTemplate
Gets or sets the DataTemplate used to display the control's content while in "Off" state.
OffContentTemplateSelector DataTemplateSelector
Gets or sets a template selector for OffContent property that enables an application writer to provide custom template-selection logic .
OnCommand ICommand
Gets or sets a command which will be executed when the IsOnProperty changes.
OnContent object
Provides the object content that should be displayed using the OnContentTemplate when this ToggleSwitch has state of "On".
OnContentStringFormat string
Gets or sets a composite string that specifies how to format the OnContent property if it is displayed as a string.
OnContentTemplate DataTemplate
Gets or sets the DataTemplate used to display the control's content while in "On" state.
OnContentTemplateSelector DataTemplateSelector
Gets or sets a template selector for OnContent property that enables an application writer to provide custom template-selection logic .

Methods