ToggleButton


Summary

Represents the Toggle button.

Syntax

public class ToggleButton : Control

Members

NameTypeSummary
BorderColor PropertyGets or sets the border line color.
BorderThickness PropertyGets or sets the border thickness. Property value can be set using Thickness, number, or a string new Thickness(5), new Thickness(1, 2, 3, 4), 5, "5", "1 2 3 4".
Checked EventOccurs when checked.
Click EventOccurs when clicked.
Content PropertyGets or sets the content.
CornerRadius PropertyGets or sets the border corner radius. Property value can be set using CornerRadius, number, or a string: new CornerRadius(5), new CornerRadius(1, 2, 3, 4).
IsChecked PropertyDefines whether the Toggle button is checked.
Text PropertyGets or sets the text.
ToggleButton MethodInitializes a new instance of the Toggle button class.
Unchecked EventOccurs when unchecked.

Example 1

using cAlgo.API;
using System;
using System.Linq;
namespace cAlgo
{
    // This sample indicator shows how to use ToggleButton control and handle its checked/unchecked events
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ToggleButtonSample : Indicator
    {
        protected override void Initialize()
        {
            var stackPanel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                BackgroundColor = Color.Gold,
                Opacity = 0.7
            };
            for (int i = 0; i < 5; i++)
            {
                var toggleButton = new ToggleButton
                {
                    Text = "Toggle Button #" + i + " Unchecked",
                    Margin = 10
                };
                toggleButton.Checked += ToggleButton_Checked;
                toggleButton.Unchecked += ToggleButton_Unchecked;
                stackPanel.AddChild(toggleButton);
            }
            Chart.AddControl(stackPanel);
        }
        private void ToggleButton_Checked(ToggleButtonEventArgs obj)
        {
            var textSplit = obj.ToggleButton.Text.Split(' ').TakeWhile(text => !text.Equals("Unchecked", StringComparison.OrdinalIgnoreCase)).ToArray();
            obj.ToggleButton.Text = string.Join(" ", textSplit) + " Checked";
        }
        private void ToggleButton_Unchecked(ToggleButtonEventArgs obj)
        {
            var textSplit = obj.ToggleButton.Text.Split(' ').TakeWhile(text => !text.Equals("Checked", StringComparison.OrdinalIgnoreCase)).ToArray();
            obj.ToggleButton.Text = string.Join(" ", textSplit) + " Unchecked";
        }
        public override void Calculate(int index)
        {
        }
    }
}
Reference