A customizable ToggleSwitch Control for WPF applications built on the .NET Core v6.0 framework. This control provides a simple and intuitive way for users to toggle a setting on or off with customizable "on" and "off" text labels.
- Customizable "on" and "off" text labels
- Visual indication of the current setting state (on/off)
- Simple and intuitive user interface
- Built-in event handling for setting change events
To use the ToggleSwitch Control in your WPF application, follow these steps:
Clone or download the source code from GitHub and add the ToggleSwitch Control to your project.
In the XAML file where you want to use the control, add the following namespace declaration to the top:
xmlns:controls="clr-namespace:YourNamespace.Controls;assembly=YourAssemblyName"
Replace YourNamespace
with the actual namespace of the ToggleSwitch Control in your project and YourAssemblyName
with the actual name of your assembly.
Add the ToggleSwitch Control to your XAML layout:
<controls:ToggleSwitch x:Name="MyToggleSwitch" OnText="Enabled" OffText="Disabled" />
To handle setting change events, add an event handler in the code-behind:
public MainWindow()
{
InitializeComponent();
MyToggleSwitch.IsOnChanged = MyToggleSwitch_IsOnChanged;
}
private void MyToggleSwitch_IsOnChanged(object sender, DependencyPropertyChangedEventArgs e)
{
// Handle the IsOnChanged event here.
// You can use MyToggleSwitch.IsOn to get the current state of the ToggleSwitch.
}
The ToggleSwitch Control has the following dependency properties:
OnText
(string): The text to display when the control is in the "on" position. Default value: "On".OffText
(string): The text to display when the control is in the "off" position. Default value: "Off".IsOn
(bool): The current state of the control. Default value:false
.
The ToggleSwitch Control has one built-in event: IsOnChanged
. This event is fired whenever the IsOn
property is changed.
To customize the "on" and "off" text labels, set the OnText
and OffText
properties in XAML:
<controls:ToggleSwitch x:Name="MyToggleSwitch" OnText="Active" OffText="Inactive" />
You can customize the appearance of the ToggleSwitch Control by modifying the XAML template in the ToggleSwitchControl.xaml
file. For example, you can change the background color, text color, and corner radius.
This project is licensed under the MIT License. See the LICENSE file for details.
Add the ToggleSwitch Control to your XAML layout with default "On" and "Off" text labels:
<controls:ToggleSwitch x:Name="MyToggleSwitch" />
Add the ToggleSwitch Control to your XAML layout with custom "On" and "Off" text labels:
```xaml
<controls:ToggleSwitch x:Name="MyToggleSwitch" OnText="Enabled" OffText="Disabled" />
Bind the IsOn
property of the ToggleSwitch Control to a property in your ViewModel:
<controls:ToggleSwitch x:Name="MyToggleSwitch" IsOn="{Binding MyBooleanProperty, Mode=TwoWay}" />
If you'd like to contribute to the development of the ToggleSwitch Control, please follow these guidelines:
- Fork the repository on GitHub.
- Create a branch for your changes.
- Make your changes and commit them to your branch.
- Create a pull request with a description of your changes.
All contributions are greatly appreciated!
If you encounter any issues or have questions about the ToggleSwitch Control, please create an issue on the GitHub repository, and we will do our best to help you.
ToggleSwitch Control was developed by Jon M. Sales as an open-source project. Special thanks to all contributors and users of the control.
Happy coding!