ToggleButton | #Widget | ToggleButton Widget For Android Dev

 by   zcweng Java Updated: 8 months ago - Current License: MIT

Download this library from

Build Applications

kandi X-RAY | ToggleButton REVIEW AND RATINGS

ToggleButton Widget For Android Developers. <img src="./images/device-2014-08-31-231538.png" width="300" height="500"/>.

kandi-support
Support

  • ToggleButton has a medium active ecosystem.
  • It has 2095 star(s) with 710 fork(s).
  • It had no major release in the last 12 months.
  • On average issues are closed in 163 days.
  • It has a neutral sentiment in the developer community.

quality kandi
Quality

  • ToggleButton has 0 bugs and 6 code smells.

security
Security

  • ToggleButton has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • ToggleButton code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.

license
License

  • ToggleButton is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.

build
Reuse

  • ToggleButton releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • ToggleButton saves you 143 person hours of effort in developing the same functionality from scratch.
  • It has 358 lines of code, 26 functions and 11 files with 0 % test coverage
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA

kandi has reviewed ToggleButton and discovered the below as its top functions. This is intended to give you an instant insight into ToggleButton implemented functionality, and help decide if they suit your requirements.

  • Sets up the View .
  • Calculates the effect of the Ripple effect .
  • draw a rectangle
  • region > measure
  • Adjusts the layout
  • Sets the activity to be saved .

ToggleButton Key Features

ToggleButton Widget For Android Dev

ToggleButton examples and code snippets

  • default
  • How to style ToggleButon in material-ui
  • Run Storyboard inside DataTemplate when an event occurs
  • RadioButton with custom image and text change at runtime
  • Get the value from input when button is clicked
  • How to add sub-options under options in select dropdown menu in react?
  • showing record text with red color when click stop button
  • In backdraftjs can you trigger a component re-render from within the component?
  • word-wrap not working in react-bootstrap navbar
  • Сombobox closes when I try to click on the elements inside WPF
  • How to use v-model on a slot in vue 3?

default

        xmlns:toggle="http://schemas.android.com/apk/res-auto"


        &lt;com.zcw.togglebutton.ToggleButton
            android:layout_width="54dp"
            toggle:tbOnColor="#f00"
            toggle:tbOffColor="#ddd"
            toggle:tbSpotColor="#00f"
            toggle:tbOffBorderColor="#000"
            toggle:tbBorderWidth="2dp"
            android:layout_height="30dp" &gt;
        &lt;/com.zcw.togglebutton.ToggleButton&gt;

How to style ToggleButon in material-ui

const useStyles = makeStyles((theme) => ({
  toggleButtonSelected: {
    "&.MuiToggleButton-root": {
      "background-color": "red"
    }
  }
}));

Run Storyboard inside DataTemplate when an event occurs

using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace WinClient
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public MainViewModel()
        {
            IsChecked = true;
        }

        private bool _isChecked;
        public bool IsChecked
        {
            set
            {
                _isChecked = value;
                OnPropertyChanged();
            }
            get
            {
                return _isChecked;
            }
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion INotifyPropertyChanged
    }
}
<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="800" Width="450">
    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DataContext.IsChecked, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="False">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard AutoReverse="False">
                                            <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="0:0:0.25" From="-100" To="0" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <Border.RenderTransform>
                    <TranslateTransform/>
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png" />
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="{Binding IsChecked}">
                    <Image Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsChecked}" Value="False">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                                        <DoubleAnimation.EasingFunction>
                                                            <PowerEase EasingMode="EaseIn" />
                                                        </DoubleAnimation.EasingFunction>
                                                    </DoubleAnimation>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                        <DataTrigger.ExitActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                                        <DoubleAnimation.EasingFunction>
                                                            <PowerEase EasingMode="EaseIn" />
                                                        </DoubleAnimation.EasingFunction>
                                                    </DoubleAnimation>                                                
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.ExitActions>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Items>
                <sys:Int32>1</sys:Int32>
                <sys:Int32>2</sys:Int32>
                <sys:Int32>3</sys:Int32>
            </ItemsControl.Items>
        </ItemsControl>
    </StackPanel>
</Window>
-----------------------
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace WinClient
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public MainViewModel()
        {
            IsChecked = true;
        }

        private bool _isChecked;
        public bool IsChecked
        {
            set
            {
                _isChecked = value;
                OnPropertyChanged();
            }
            get
            {
                return _isChecked;
            }
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion INotifyPropertyChanged
    }
}
<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="800" Width="450">
    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DataContext.IsChecked, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="False">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard AutoReverse="False">
                                            <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="0:0:0.25" From="-100" To="0" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <Border.RenderTransform>
                    <TranslateTransform/>
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png" />
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="{Binding IsChecked}">
                    <Image Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsChecked}" Value="False">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                                        <DoubleAnimation.EasingFunction>
                                                            <PowerEase EasingMode="EaseIn" />
                                                        </DoubleAnimation.EasingFunction>
                                                    </DoubleAnimation>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                        <DataTrigger.ExitActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                                        <DoubleAnimation.EasingFunction>
                                                            <PowerEase EasingMode="EaseIn" />
                                                        </DoubleAnimation.EasingFunction>
                                                    </DoubleAnimation>                                                
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.ExitActions>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Items>
                <sys:Int32>1</sys:Int32>
                <sys:Int32>2</sys:Int32>
                <sys:Int32>3</sys:Int32>
            </ItemsControl.Items>
        </ItemsControl>
    </StackPanel>
</Window>
-----------------------
<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient" xmlns:specialized="clr-namespace:System.Collections.Specialized;assembly=System" xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <specialized:StringCollection x:Key="source">
            <sys:String>First</sys:String>
            <sys:String>Second</sys:String>
        </specialized:StringCollection>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.RenderTransform>
                    <TranslateTransform Y="{Binding Tag, ElementName=itemsControl}" />
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="True" >
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:0.25" From="-100" To="0" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Tag>
                <sys:Double>10</sys:Double>
            </ItemsControl.Tag>
        </ItemsControl>
    </StackPanel>
</Window>
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace WinClient
{
    public class MultiplicationConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length == 0)
                return DependencyProperty.UnsetValue;

            double product = 1;
            foreach (var value in values)
            {
                if (double.TryParse(value.ToString(), out double number))
                    product *= number;
                if (product == 0)
                    break;
            }
            return product;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static MultiplicationConverter Instance { get; } = new MultiplicationConverter();
    }

    public class MultiplicationConverterExtension : MarkupExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
            => MultiplicationConverter.Instance;
    }
}

<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
        <sys:Double x:Key="zero">0</sys:Double>
        <ItemsPanelTemplate x:Key="canvasTemplate">
            <Canvas/>
        </ItemsPanelTemplate>
        <Style x:Key="itemContainerStyle" TargetType="ContentPresenter">
            <Setter Property="Canvas.Top">
                <Setter.Value>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="(ItemsControl.AlternationIndex)" RelativeSource="{RelativeSource Self}"/>
                        <Binding Path="Tag" ElementName="itemsControl"/>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid VerticalAlignment="Top" Margin="50" HorizontalAlignment="Center">
        <Border x:Name="border" Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121"
                Panel.ZIndex="10">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom">
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" To="0" From="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" To="0" From="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" From="0" To="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" From="0" To="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      AlternationCount="{x:Static sys:Int32.MaxValue}"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{DynamicResource ShortcutButton}"
                      Tag="{StaticResource zero}"
                      ItemsPanel="{DynamicResource canvasTemplate}"
                      ItemContainerStyle="{DynamicResource itemContainerStyle}" RenderTransformOrigin="0.5,0.5">
            <ItemsControl.RenderTransform>
                <TranslateTransform x:Name="itemsControlXY" Y="0"/>
            </ItemsControl.RenderTransform>
        </ItemsControl>
    </Grid>
</Window>
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <sys:Double x:Key="percent">0.01</sys:Double>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="AliceBlue" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Opacity>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="Tag" ElementName="itemsControl"/>
                        <Binding Source="{StaticResource percent}"/>
                    </MultiBinding>
                </Border.Opacity>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
-----------------------
<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient" xmlns:specialized="clr-namespace:System.Collections.Specialized;assembly=System" xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <specialized:StringCollection x:Key="source">
            <sys:String>First</sys:String>
            <sys:String>Second</sys:String>
        </specialized:StringCollection>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.RenderTransform>
                    <TranslateTransform Y="{Binding Tag, ElementName=itemsControl}" />
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="True" >
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:0.25" From="-100" To="0" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Tag>
                <sys:Double>10</sys:Double>
            </ItemsControl.Tag>
        </ItemsControl>
    </StackPanel>
</Window>
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace WinClient
{
    public class MultiplicationConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length == 0)
                return DependencyProperty.UnsetValue;

            double product = 1;
            foreach (var value in values)
            {
                if (double.TryParse(value.ToString(), out double number))
                    product *= number;
                if (product == 0)
                    break;
            }
            return product;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static MultiplicationConverter Instance { get; } = new MultiplicationConverter();
    }

    public class MultiplicationConverterExtension : MarkupExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
            => MultiplicationConverter.Instance;
    }
}

<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
        <sys:Double x:Key="zero">0</sys:Double>
        <ItemsPanelTemplate x:Key="canvasTemplate">
            <Canvas/>
        </ItemsPanelTemplate>
        <Style x:Key="itemContainerStyle" TargetType="ContentPresenter">
            <Setter Property="Canvas.Top">
                <Setter.Value>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="(ItemsControl.AlternationIndex)" RelativeSource="{RelativeSource Self}"/>
                        <Binding Path="Tag" ElementName="itemsControl"/>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid VerticalAlignment="Top" Margin="50" HorizontalAlignment="Center">
        <Border x:Name="border" Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121"
                Panel.ZIndex="10">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom">
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" To="0" From="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" To="0" From="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" From="0" To="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" From="0" To="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      AlternationCount="{x:Static sys:Int32.MaxValue}"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{DynamicResource ShortcutButton}"
                      Tag="{StaticResource zero}"
                      ItemsPanel="{DynamicResource canvasTemplate}"
                      ItemContainerStyle="{DynamicResource itemContainerStyle}" RenderTransformOrigin="0.5,0.5">
            <ItemsControl.RenderTransform>
                <TranslateTransform x:Name="itemsControlXY" Y="0"/>
            </ItemsControl.RenderTransform>
        </ItemsControl>
    </Grid>
</Window>
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <sys:Double x:Key="percent">0.01</sys:Double>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="AliceBlue" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Opacity>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="Tag" ElementName="itemsControl"/>
                        <Binding Source="{StaticResource percent}"/>
                    </MultiBinding>
                </Border.Opacity>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
-----------------------
<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient" xmlns:specialized="clr-namespace:System.Collections.Specialized;assembly=System" xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <specialized:StringCollection x:Key="source">
            <sys:String>First</sys:String>
            <sys:String>Second</sys:String>
        </specialized:StringCollection>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.RenderTransform>
                    <TranslateTransform Y="{Binding Tag, ElementName=itemsControl}" />
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="True" >
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:0.25" From="-100" To="0" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Tag>
                <sys:Double>10</sys:Double>
            </ItemsControl.Tag>
        </ItemsControl>
    </StackPanel>
</Window>
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace WinClient
{
    public class MultiplicationConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length == 0)
                return DependencyProperty.UnsetValue;

            double product = 1;
            foreach (var value in values)
            {
                if (double.TryParse(value.ToString(), out double number))
                    product *= number;
                if (product == 0)
                    break;
            }
            return product;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static MultiplicationConverter Instance { get; } = new MultiplicationConverter();
    }

    public class MultiplicationConverterExtension : MarkupExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
            => MultiplicationConverter.Instance;
    }
}

<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
        <sys:Double x:Key="zero">0</sys:Double>
        <ItemsPanelTemplate x:Key="canvasTemplate">
            <Canvas/>
        </ItemsPanelTemplate>
        <Style x:Key="itemContainerStyle" TargetType="ContentPresenter">
            <Setter Property="Canvas.Top">
                <Setter.Value>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="(ItemsControl.AlternationIndex)" RelativeSource="{RelativeSource Self}"/>
                        <Binding Path="Tag" ElementName="itemsControl"/>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid VerticalAlignment="Top" Margin="50" HorizontalAlignment="Center">
        <Border x:Name="border" Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121"
                Panel.ZIndex="10">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom">
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" To="0" From="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" To="0" From="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" From="0" To="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" From="0" To="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      AlternationCount="{x:Static sys:Int32.MaxValue}"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{DynamicResource ShortcutButton}"
                      Tag="{StaticResource zero}"
                      ItemsPanel="{DynamicResource canvasTemplate}"
                      ItemContainerStyle="{DynamicResource itemContainerStyle}" RenderTransformOrigin="0.5,0.5">
            <ItemsControl.RenderTransform>
                <TranslateTransform x:Name="itemsControlXY" Y="0"/>
            </ItemsControl.RenderTransform>
        </ItemsControl>
    </Grid>
</Window>
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <sys:Double x:Key="percent">0.01</sys:Double>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="AliceBlue" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Opacity>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="Tag" ElementName="itemsControl"/>
                        <Binding Source="{StaticResource percent}"/>
                    </MultiBinding>
                </Border.Opacity>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
-----------------------
<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient" xmlns:specialized="clr-namespace:System.Collections.Specialized;assembly=System" xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <specialized:StringCollection x:Key="source">
            <sys:String>First</sys:String>
            <sys:String>Second</sys:String>
        </specialized:StringCollection>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.RenderTransform>
                    <TranslateTransform Y="{Binding Tag, ElementName=itemsControl}" />
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="True" >
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:0.25" From="-100" To="0" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Tag>
                <sys:Double>10</sys:Double>
            </ItemsControl.Tag>
        </ItemsControl>
    </StackPanel>
</Window>
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace WinClient
{
    public class MultiplicationConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length == 0)
                return DependencyProperty.UnsetValue;

            double product = 1;
            foreach (var value in values)
            {
                if (double.TryParse(value.ToString(), out double number))
                    product *= number;
                if (product == 0)
                    break;
            }
            return product;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static MultiplicationConverter Instance { get; } = new MultiplicationConverter();
    }

    public class MultiplicationConverterExtension : MarkupExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
            => MultiplicationConverter.Instance;
    }
}

<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="650" Width="800">
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
        <sys:Double x:Key="zero">0</sys:Double>
        <ItemsPanelTemplate x:Key="canvasTemplate">
            <Canvas/>
        </ItemsPanelTemplate>
        <Style x:Key="itemContainerStyle" TargetType="ContentPresenter">
            <Setter Property="Canvas.Top">
                <Setter.Value>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="(ItemsControl.AlternationIndex)" RelativeSource="{RelativeSource Self}"/>
                        <Binding Path="Tag" ElementName="itemsControl"/>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid VerticalAlignment="Top" Margin="50" HorizontalAlignment="Center">
        <Border x:Name="border" Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121"
                Panel.ZIndex="10">
            <Grid>
                <Image Source="Resources/logo.png"/>
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom">
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" To="0" From="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" To="0" From="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                    <DoubleAnimation Storyboard.TargetName="itemsControl" Storyboard.TargetProperty="Tag" Duration="0:0:2" From="0" To="100" />
                                    <DoubleAnimation Storyboard.TargetName="itemsControlXY" Storyboard.TargetProperty="Y" Duration="0:0:2" From="0" To="{Binding ActualHeight, ElementName=border}" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl x:Name="itemsControl"
                      AlternationCount="{x:Static sys:Int32.MaxValue}"
                      ItemsSource="{DynamicResource source}"
                      ItemTemplate="{DynamicResource ShortcutButton}"
                      Tag="{StaticResource zero}"
                      ItemsPanel="{DynamicResource canvasTemplate}"
                      ItemContainerStyle="{DynamicResource itemContainerStyle}" RenderTransformOrigin="0.5,0.5">
            <ItemsControl.RenderTransform>
                <TranslateTransform x:Name="itemsControlXY" Y="0"/>
            </ItemsControl.RenderTransform>
        </ItemsControl>
    </Grid>
</Window>
    <Window.Resources>
        <sys:String x:Key="source">12345</sys:String>
        <sys:Double x:Key="percent">0.01</sys:Double>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="AliceBlue" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Opacity>
                    <MultiBinding Converter="{local:MultiplicationConverter}">
                        <Binding Path="Tag" ElementName="itemsControl"/>
                        <Binding Source="{StaticResource percent}"/>
                    </MultiBinding>
                </Border.Opacity>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>

RadioButton with custom image and text change at runtime

public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}
<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"
public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}
<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>
<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");
-----------------------
    public class ButtonContent
    {
        public string Strona { get; set; }
        public string Login { get; set; }
        public object ImageSource { get; set; }
    }
        <Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}" >

            <Setter Property="Background" Value="#32353B" />
            <Setter Property="Margin" Value="10,5"/>
            <Setter Property="Height" Value="45" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Padding" Value="1" />
            <Setter Property="HorizontalAlignment" Value="Stretch"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <StackPanel>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            Background="{TemplateBinding Background}">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0">
                                    <ContentPresenter HorizontalAlignment="Left"                  
                                          VerticalAlignment="Center"/>

                                    <Image Source="{Binding ImageSource}"
                                           HorizontalAlignment="Left" Stretch="Uniform" Width="45" IsEnabled="True" />

                                    <StackPanel Margin="2">
                                        <TextBlock Foreground="#DCDDDE"  FontSize="18" FontFamily="Arial"
                                                   Text="{Binding Strona}"/>
                                        <TextBlock Foreground="#52555C"  FontSize="12" FontFamily="Arial"
                                                   Text="{Binding Login}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>

                    </ControlTemplate>

                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="#282B2E"/>
                </Trigger>

                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="#FF282B2E" Opacity="0.5"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="itemTemplate" DataType="{x:Type local:ButtonContent}">
            <ToggleButton Style="{DynamicResource ToggleButton_Chose}"/>
        </DataTemplate>
        <ItemsControl x:Name="itemsControl"
                      ItemTemplate="{DynamicResource itemTemplate}">
        </ItemsControl>
    public partial class MainWindow : Window
    {
        private readonly ObservableCollection<ButtonContent> ButtonContents
            = new ObservableCollection<ButtonContent>();
        public MainWindow()
        {
            InitializeComponent();
            itemsControl.ItemsSource = ButtonContents;
            ButtonContents.Add(new ButtonContent() { Strona = "Strona1", Login = "Login1", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona2", Login = "Login2", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona3", Login = "Login3", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona4", Login = "Login4", ImageSource = "Image/block.png" });
        }

    }
-----------------------
    public class ButtonContent
    {
        public string Strona { get; set; }
        public string Login { get; set; }
        public object ImageSource { get; set; }
    }
        <Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}" >

            <Setter Property="Background" Value="#32353B" />
            <Setter Property="Margin" Value="10,5"/>
            <Setter Property="Height" Value="45" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Padding" Value="1" />
            <Setter Property="HorizontalAlignment" Value="Stretch"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <StackPanel>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            Background="{TemplateBinding Background}">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0">
                                    <ContentPresenter HorizontalAlignment="Left"                  
                                          VerticalAlignment="Center"/>

                                    <Image Source="{Binding ImageSource}"
                                           HorizontalAlignment="Left" Stretch="Uniform" Width="45" IsEnabled="True" />

                                    <StackPanel Margin="2">
                                        <TextBlock Foreground="#DCDDDE"  FontSize="18" FontFamily="Arial"
                                                   Text="{Binding Strona}"/>
                                        <TextBlock Foreground="#52555C"  FontSize="12" FontFamily="Arial"
                                                   Text="{Binding Login}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>

                    </ControlTemplate>

                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="#282B2E"/>
                </Trigger>

                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="#FF282B2E" Opacity="0.5"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="itemTemplate" DataType="{x:Type local:ButtonContent}">
            <ToggleButton Style="{DynamicResource ToggleButton_Chose}"/>
        </DataTemplate>
        <ItemsControl x:Name="itemsControl"
                      ItemTemplate="{DynamicResource itemTemplate}">
        </ItemsControl>
    public partial class MainWindow : Window
    {
        private readonly ObservableCollection<ButtonContent> ButtonContents
            = new ObservableCollection<ButtonContent>();
        public MainWindow()
        {
            InitializeComponent();
            itemsControl.ItemsSource = ButtonContents;
            ButtonContents.Add(new ButtonContent() { Strona = "Strona1", Login = "Login1", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona2", Login = "Login2", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona3", Login = "Login3", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona4", Login = "Login4", ImageSource = "Image/block.png" });
        }

    }
-----------------------
    public class ButtonContent
    {
        public string Strona { get; set; }
        public string Login { get; set; }
        public object ImageSource { get; set; }
    }
        <Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}" >

            <Setter Property="Background" Value="#32353B" />
            <Setter Property="Margin" Value="10,5"/>
            <Setter Property="Height" Value="45" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Padding" Value="1" />
            <Setter Property="HorizontalAlignment" Value="Stretch"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <StackPanel>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            Background="{TemplateBinding Background}">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0">
                                    <ContentPresenter HorizontalAlignment="Left"                  
                                          VerticalAlignment="Center"/>

                                    <Image Source="{Binding ImageSource}"
                                           HorizontalAlignment="Left" Stretch="Uniform" Width="45" IsEnabled="True" />

                                    <StackPanel Margin="2">
                                        <TextBlock Foreground="#DCDDDE"  FontSize="18" FontFamily="Arial"
                                                   Text="{Binding Strona}"/>
                                        <TextBlock Foreground="#52555C"  FontSize="12" FontFamily="Arial"
                                                   Text="{Binding Login}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>

                    </ControlTemplate>

                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="#282B2E"/>
                </Trigger>

                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="#FF282B2E" Opacity="0.5"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="itemTemplate" DataType="{x:Type local:ButtonContent}">
            <ToggleButton Style="{DynamicResource ToggleButton_Chose}"/>
        </DataTemplate>
        <ItemsControl x:Name="itemsControl"
                      ItemTemplate="{DynamicResource itemTemplate}">
        </ItemsControl>
    public partial class MainWindow : Window
    {
        private readonly ObservableCollection<ButtonContent> ButtonContents
            = new ObservableCollection<ButtonContent>();
        public MainWindow()
        {
            InitializeComponent();
            itemsControl.ItemsSource = ButtonContents;
            ButtonContents.Add(new ButtonContent() { Strona = "Strona1", Login = "Login1", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona2", Login = "Login2", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona3", Login = "Login3", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona4", Login = "Login4", ImageSource = "Image/block.png" });
        }

    }
-----------------------
    public class ButtonContent
    {
        public string Strona { get; set; }
        public string Login { get; set; }
        public object ImageSource { get; set; }
    }
        <Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}" >

            <Setter Property="Background" Value="#32353B" />
            <Setter Property="Margin" Value="10,5"/>
            <Setter Property="Height" Value="45" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Padding" Value="1" />
            <Setter Property="HorizontalAlignment" Value="Stretch"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <StackPanel>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            Background="{TemplateBinding Background}">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0">
                                    <ContentPresenter HorizontalAlignment="Left"                  
                                          VerticalAlignment="Center"/>

                                    <Image Source="{Binding ImageSource}"
                                           HorizontalAlignment="Left" Stretch="Uniform" Width="45" IsEnabled="True" />

                                    <StackPanel Margin="2">
                                        <TextBlock Foreground="#DCDDDE"  FontSize="18" FontFamily="Arial"
                                                   Text="{Binding Strona}"/>
                                        <TextBlock Foreground="#52555C"  FontSize="12" FontFamily="Arial"
                                                   Text="{Binding Login}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>

                    </ControlTemplate>

                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="#282B2E"/>
                </Trigger>

                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="#FF282B2E" Opacity="0.5"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="itemTemplate" DataType="{x:Type local:ButtonContent}">
            <ToggleButton Style="{DynamicResource ToggleButton_Chose}"/>
        </DataTemplate>
        <ItemsControl x:Name="itemsControl"
                      ItemTemplate="{DynamicResource itemTemplate}">
        </ItemsControl>
    public partial class MainWindow : Window
    {
        private readonly ObservableCollection<ButtonContent> ButtonContents
            = new ObservableCollection<ButtonContent>();
        public MainWindow()
        {
            InitializeComponent();
            itemsControl.ItemsSource = ButtonContents;
            ButtonContents.Add(new ButtonContent() { Strona = "Strona1", Login = "Login1", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona2", Login = "Login2", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona3", Login = "Login3", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona4", Login = "Login4", ImageSource = "Image/block.png" });
        }

    }
-----------------------
    public class ButtonContent
    {
        public string Strona { get; set; }
        public string Login { get; set; }
        public object ImageSource { get; set; }
    }
        <Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}" >

            <Setter Property="Background" Value="#32353B" />
            <Setter Property="Margin" Value="10,5"/>
            <Setter Property="Height" Value="45" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="Padding" Value="1" />
            <Setter Property="HorizontalAlignment" Value="Stretch"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <StackPanel>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            Background="{TemplateBinding Background}">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0">
                                    <ContentPresenter HorizontalAlignment="Left"                  
                                          VerticalAlignment="Center"/>

                                    <Image Source="{Binding ImageSource}"
                                           HorizontalAlignment="Left" Stretch="Uniform" Width="45" IsEnabled="True" />

                                    <StackPanel Margin="2">
                                        <TextBlock Foreground="#DCDDDE"  FontSize="18" FontFamily="Arial"
                                                   Text="{Binding Strona}"/>
                                        <TextBlock Foreground="#52555C"  FontSize="12" FontFamily="Arial"
                                                   Text="{Binding Login}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>

                    </ControlTemplate>

                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter Property="Background" Value="#282B2E"/>
                </Trigger>

                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="#FF282B2E" Opacity="0.5"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="itemTemplate" DataType="{x:Type local:ButtonContent}">
            <ToggleButton Style="{DynamicResource ToggleButton_Chose}"/>
        </DataTemplate>
        <ItemsControl x:Name="itemsControl"
                      ItemTemplate="{DynamicResource itemTemplate}">
        </ItemsControl>
    public partial class MainWindow : Window
    {
        private readonly ObservableCollection<ButtonContent> ButtonContents
            = new ObservableCollection<ButtonContent>();
        public MainWindow()
        {
            InitializeComponent();
            itemsControl.ItemsSource = ButtonContents;
            ButtonContents.Add(new ButtonContent() { Strona = "Strona1", Login = "Login1", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona2", Login = "Login2", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona3", Login = "Login3", ImageSource = "Image/block.png" });
            ButtonContents.Add(new ButtonContent() { Strona = "Strona4", Login = "Login4", ImageSource = "Image/block.png" });
        }

    }

Get the value from input when button is clicked

const {useState, useEffect} = React;

function Example() {

  const [input, setInput] = useState('');

  useEffect(() => {
    console.log(`State: ${input}`);
  }, [input])

  function handleClick() {
    setInput('');
  }

  function handleInput(e) {
    const { target: { value } } = e;
    setInput(value);
  }

  return (
    <div>
      <div>
        <input onChange={handleInput} type="text" placeholder="search" value={input} />
        <button onClick={handleClick}>reset</button>
      </div>
    </div>
  );

};

// Render it
ReactDOM.render(
  <Example />,
  document.getElementById("react")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>
-----------------------
const {useState, useEffect} = React;

function Example() {

  const [input, setInput] = useState('');

  useEffect(() => {
    console.log(`State: ${input}`);
  }, [input])

  function handleClick() {
    setInput('');
  }

  function handleInput(e) {
    const { target: { value } } = e;
    setInput(value);
  }

  return (
    <div>
      <div>
        <input onChange={handleInput} type="text" placeholder="search" value={input} />
        <button onClick={handleClick}>reset</button>
      </div>
    </div>
  );

};

// Render it
ReactDOM.render(
  <Example />,
  document.getElementById("react")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>

How to add sub-options under options in select dropdown menu in react?

render() {
    return (
     <div >
      <select className="togglebutton" >
      <option selected disabled>Choose here</option>
        {this.state.options.map((option, key) => (
       
        <option key={key}>{option["key"]}</option>
         
         <optgroup label={option["key"]}>
            {this.state.subOptions.map((subOption, key) => (
              <option>{subOption.key}</option>
            ))}
             // OR

           {this.state.option["key"].subOptions.map((subOpt,i) => (
              <option>{subOpt.i}</option>
            ))}
           
         </optgroup>
   
       ))}
     </select>
   </div>
 );
}    

showing record text with red color when click stop button

const scoreBoard = document.querySelector('#score_board');
const score = document.getElementById("time").innerHTML;
const scoreEl = document.createElement('p');
if(c) scoreEl.style.color = 'red';
const node = document.createTextNode(score);
scoreEl.appendChild(node);
scoreBoard.appendChild(scoreEl);
var answer = 0;

function start() {
  startTime = new Date().getTime();
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Stop";
  toggleButton.onclick = stop;

  init();

  timer = setInterval(function() {
    now = new Date().getTime();
    seconds = now - startTime;
    document.getElementById("time").innerHTML = displayTime(seconds);
  }, 60);
}

function stop(c) {
  clearInterval(timer);
  const scoreBoard = document.querySelector('#score_board');
  const score = document.getElementById("time").innerHTML;
  const scoreEl = document.createElement('p');
  if(c) scoreEl.style.color = 'red';
  const node = document.createTextNode(score);
  scoreEl.appendChild(node);
  scoreBoard.appendChild(scoreEl);
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Start";
  toggleButton.onclick = start;
}

function btnClick(num) {
  btns = document.getElementsByClassName("btn");
  if (num == answer) { 
    answer = answer+1;
    btns[num].disabled = true;
    if (num == 8) { 
      stop();
    }
  } else { 
    init();
  }
}

function init() {
  answer = 0;

  btns = document.getElementsByClassName("btn");
  for (let index=0; index<btns.length; index++) {
    btns[index].disabled = false;
    btns[index].innerHTML = index;
  }
}

function displayTime (seconds) {
  m = String(Math.floor(seconds / 1000 / 60));
  s = String(Math.floor((seconds / 1000) % 60));
  ms = String(Math.floor(seconds % 100));
  return m.padStart(2, '0') + ":" + s.padStart(2, '0') + ":" + ms.padStart(2, '0');
};
.btn {
  width:60px;
  height:60px;
  font-size:18px;
  margin:2px;
} /*select by class */

#toggle_button {
  width:120px;
  background-color:#000;
  color:#fff;
  height:24px;
  border:none;
}

#time {
  font-size:20px;
  font-weight:bold;
} /*select by id */

img {
  width:100px;
} /*select by html elemnt */
<center>
  <p id="time">00:00:00</p>
  <button id="toggle_button" onclick="start()">Start</button>
  <br /><br />

  <button id="button_1" class="btn" onclick="btnClick(0)" disabled>?</button>
  <button id="button_2" class="btn" onclick="btnClick(1)" disabled>?</button>
  <button id="button_3" class="btn" onclick="btnClick(2)" disabled>?</button><br />
  <button id="button_4" class="btn" onclick="btnClick(3)" disabled>?</button>
  <button id="button_5" class="btn" onclick="btnClick(4)" disabled>?</button>
  <button id="button_6" class="btn" onclick="btnClick(5)" disabled>?</button><br />
  <button id="button_7" class="btn" onclick="btnClick(6)" disabled>?</button>
  <button id="button_8" class="btn" onclick="btnClick(7)" disabled>?</button>
  <button id="button_9" class="btn" onclick="btnClick(8)" disabled>?</button>

  <div id="score_board">
    <p><strong>Score Board</strong><p>
  </div>
</center>
-----------------------
const scoreBoard = document.querySelector('#score_board');
const score = document.getElementById("time").innerHTML;
const scoreEl = document.createElement('p');
if(c) scoreEl.style.color = 'red';
const node = document.createTextNode(score);
scoreEl.appendChild(node);
scoreBoard.appendChild(scoreEl);
var answer = 0;

function start() {
  startTime = new Date().getTime();
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Stop";
  toggleButton.onclick = stop;

  init();

  timer = setInterval(function() {
    now = new Date().getTime();
    seconds = now - startTime;
    document.getElementById("time").innerHTML = displayTime(seconds);
  }, 60);
}

function stop(c) {
  clearInterval(timer);
  const scoreBoard = document.querySelector('#score_board');
  const score = document.getElementById("time").innerHTML;
  const scoreEl = document.createElement('p');
  if(c) scoreEl.style.color = 'red';
  const node = document.createTextNode(score);
  scoreEl.appendChild(node);
  scoreBoard.appendChild(scoreEl);
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Start";
  toggleButton.onclick = start;
}

function btnClick(num) {
  btns = document.getElementsByClassName("btn");
  if (num == answer) { 
    answer = answer+1;
    btns[num].disabled = true;
    if (num == 8) { 
      stop();
    }
  } else { 
    init();
  }
}

function init() {
  answer = 0;

  btns = document.getElementsByClassName("btn");
  for (let index=0; index<btns.length; index++) {
    btns[index].disabled = false;
    btns[index].innerHTML = index;
  }
}

function displayTime (seconds) {
  m = String(Math.floor(seconds / 1000 / 60));
  s = String(Math.floor((seconds / 1000) % 60));
  ms = String(Math.floor(seconds % 100));
  return m.padStart(2, '0') + ":" + s.padStart(2, '0') + ":" + ms.padStart(2, '0');
};
.btn {
  width:60px;
  height:60px;
  font-size:18px;
  margin:2px;
} /*select by class */

#toggle_button {
  width:120px;
  background-color:#000;
  color:#fff;
  height:24px;
  border:none;
}

#time {
  font-size:20px;
  font-weight:bold;
} /*select by id */

img {
  width:100px;
} /*select by html elemnt */
<center>
  <p id="time">00:00:00</p>
  <button id="toggle_button" onclick="start()">Start</button>
  <br /><br />

  <button id="button_1" class="btn" onclick="btnClick(0)" disabled>?</button>
  <button id="button_2" class="btn" onclick="btnClick(1)" disabled>?</button>
  <button id="button_3" class="btn" onclick="btnClick(2)" disabled>?</button><br />
  <button id="button_4" class="btn" onclick="btnClick(3)" disabled>?</button>
  <button id="button_5" class="btn" onclick="btnClick(4)" disabled>?</button>
  <button id="button_6" class="btn" onclick="btnClick(5)" disabled>?</button><br />
  <button id="button_7" class="btn" onclick="btnClick(6)" disabled>?</button>
  <button id="button_8" class="btn" onclick="btnClick(7)" disabled>?</button>
  <button id="button_9" class="btn" onclick="btnClick(8)" disabled>?</button>

  <div id="score_board">
    <p><strong>Score Board</strong><p>
  </div>
</center>
-----------------------
const scoreBoard = document.querySelector('#score_board');
const score = document.getElementById("time").innerHTML;
const scoreEl = document.createElement('p');
if(c) scoreEl.style.color = 'red';
const node = document.createTextNode(score);
scoreEl.appendChild(node);
scoreBoard.appendChild(scoreEl);
var answer = 0;

function start() {
  startTime = new Date().getTime();
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Stop";
  toggleButton.onclick = stop;

  init();

  timer = setInterval(function() {
    now = new Date().getTime();
    seconds = now - startTime;
    document.getElementById("time").innerHTML = displayTime(seconds);
  }, 60);
}

function stop(c) {
  clearInterval(timer);
  const scoreBoard = document.querySelector('#score_board');
  const score = document.getElementById("time").innerHTML;
  const scoreEl = document.createElement('p');
  if(c) scoreEl.style.color = 'red';
  const node = document.createTextNode(score);
  scoreEl.appendChild(node);
  scoreBoard.appendChild(scoreEl);
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Start";
  toggleButton.onclick = start;
}

function btnClick(num) {
  btns = document.getElementsByClassName("btn");
  if (num == answer) { 
    answer = answer+1;
    btns[num].disabled = true;
    if (num == 8) { 
      stop();
    }
  } else { 
    init();
  }
}

function init() {
  answer = 0;

  btns = document.getElementsByClassName("btn");
  for (let index=0; index<btns.length; index++) {
    btns[index].disabled = false;
    btns[index].innerHTML = index;
  }
}

function displayTime (seconds) {
  m = String(Math.floor(seconds / 1000 / 60));
  s = String(Math.floor((seconds / 1000) % 60));
  ms = String(Math.floor(seconds % 100));
  return m.padStart(2, '0') + ":" + s.padStart(2, '0') + ":" + ms.padStart(2, '0');
};
.btn {
  width:60px;
  height:60px;
  font-size:18px;
  margin:2px;
} /*select by class */

#toggle_button {
  width:120px;
  background-color:#000;
  color:#fff;
  height:24px;
  border:none;
}

#time {
  font-size:20px;
  font-weight:bold;
} /*select by id */

img {
  width:100px;
} /*select by html elemnt */
<center>
  <p id="time">00:00:00</p>
  <button id="toggle_button" onclick="start()">Start</button>
  <br /><br />

  <button id="button_1" class="btn" onclick="btnClick(0)" disabled>?</button>
  <button id="button_2" class="btn" onclick="btnClick(1)" disabled>?</button>
  <button id="button_3" class="btn" onclick="btnClick(2)" disabled>?</button><br />
  <button id="button_4" class="btn" onclick="btnClick(3)" disabled>?</button>
  <button id="button_5" class="btn" onclick="btnClick(4)" disabled>?</button>
  <button id="button_6" class="btn" onclick="btnClick(5)" disabled>?</button><br />
  <button id="button_7" class="btn" onclick="btnClick(6)" disabled>?</button>
  <button id="button_8" class="btn" onclick="btnClick(7)" disabled>?</button>
  <button id="button_9" class="btn" onclick="btnClick(8)" disabled>?</button>

  <div id="score_board">
    <p><strong>Score Board</strong><p>
  </div>
</center>
-----------------------
const scoreBoard = document.querySelector('#score_board');
const score = document.getElementById("time").innerHTML;
const scoreEl = document.createElement('p');
if(c) scoreEl.style.color = 'red';
const node = document.createTextNode(score);
scoreEl.appendChild(node);
scoreBoard.appendChild(scoreEl);
var answer = 0;

function start() {
  startTime = new Date().getTime();
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Stop";
  toggleButton.onclick = stop;

  init();

  timer = setInterval(function() {
    now = new Date().getTime();
    seconds = now - startTime;
    document.getElementById("time").innerHTML = displayTime(seconds);
  }, 60);
}

function stop(c) {
  clearInterval(timer);
  const scoreBoard = document.querySelector('#score_board');
  const score = document.getElementById("time").innerHTML;
  const scoreEl = document.createElement('p');
  if(c) scoreEl.style.color = 'red';
  const node = document.createTextNode(score);
  scoreEl.appendChild(node);
  scoreBoard.appendChild(scoreEl);
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Start";
  toggleButton.onclick = start;
}

function btnClick(num) {
  btns = document.getElementsByClassName("btn");
  if (num == answer) { 
    answer = answer+1;
    btns[num].disabled = true;
    if (num == 8) { 
      stop();
    }
  } else { 
    init();
  }
}

function init() {
  answer = 0;

  btns = document.getElementsByClassName("btn");
  for (let index=0; index<btns.length; index++) {
    btns[index].disabled = false;
    btns[index].innerHTML = index;
  }
}

function displayTime (seconds) {
  m = String(Math.floor(seconds / 1000 / 60));
  s = String(Math.floor((seconds / 1000) % 60));
  ms = String(Math.floor(seconds % 100));
  return m.padStart(2, '0') + ":" + s.padStart(2, '0') + ":" + ms.padStart(2, '0');
};
.btn {
  width:60px;
  height:60px;
  font-size:18px;
  margin:2px;
} /*select by class */

#toggle_button {
  width:120px;
  background-color:#000;
  color:#fff;
  height:24px;
  border:none;
}

#time {
  font-size:20px;
  font-weight:bold;
} /*select by id */

img {
  width:100px;
} /*select by html elemnt */
<center>
  <p id="time">00:00:00</p>
  <button id="toggle_button" onclick="start()">Start</button>
  <br /><br />

  <button id="button_1" class="btn" onclick="btnClick(0)" disabled>?</button>
  <button id="button_2" class="btn" onclick="btnClick(1)" disabled>?</button>
  <button id="button_3" class="btn" onclick="btnClick(2)" disabled>?</button><br />
  <button id="button_4" class="btn" onclick="btnClick(3)" disabled>?</button>
  <button id="button_5" class="btn" onclick="btnClick(4)" disabled>?</button>
  <button id="button_6" class="btn" onclick="btnClick(5)" disabled>?</button><br />
  <button id="button_7" class="btn" onclick="btnClick(6)" disabled>?</button>
  <button id="button_8" class="btn" onclick="btnClick(7)" disabled>?</button>
  <button id="button_9" class="btn" onclick="btnClick(8)" disabled>?</button>

  <div id="score_board">
    <p><strong>Score Board</strong><p>
  </div>
</center>

In backdraftjs can you trigger a component re-render from within the component?

class ClickButton extends Component.withWatchables('clicked') {
    bdElements() {
        return e.button(
            {
                bdReflectClass: ['clicked', value=>(value ? 'clicked' : '')],
                bdAdvise_click: e=>(this.clicked = !this.clicked)
            },
            'Click Me'
        );
    }
}

word-wrap not working in react-bootstrap navbar

<h4 className="text-wrap">Example Headline Here</h4>

Сombobox closes when I try to click on the elements inside WPF

<Window x:Class="SliderInPopup.SliderInPopupWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SliderInPopup"
        mc:Ignorable="d"
        Title="SliderInPopupWindow" Height="450" Width="800">
    <Grid>
        <ToggleButton x:Name="toggleButton" VerticalAlignment="Top" HorizontalAlignment="Left" Content="Click Me"/>
        <Popup x:Name="popup1" StaysOpen="False"
               Placement="Mouse" AllowsTransparency="True"
               IsOpen="{Binding IsChecked, ElementName=toggleButton}"  >
            <Grid Width="208" Height="108">
                <Border CornerRadius="22" BorderThickness="1" BorderBrush="Black">
                    <Border.Background>
                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <GradientStop Color="#2d2d2e" Offset="0" />
                            <GradientStop Color="#151517" Offset="1" />
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
                <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="28,20,0,0" Height="64" Width="150">
                    <TextBlock Text="Громкость" FontSize="14" Foreground="Orange" Margin="5,0,0,0" />
                    <Slider Margin="0,14,0,0" Name="SoundSlider" TickFrequency="1" IsSelectionRangeEnabled="True" Minimum="0" Maximum="9" SelectionStart="0" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </StackPanel>
            </Grid>
        </Popup>
    </Grid>
</Window>

How to use v-model on a slot in vue 3?

<template>
  <div class="hello">
    <PopoverModal>
      <template #toggleButton>
        <button>A</button>
      </template>
      <template #modalContent="modelContent">
        <div style="color: #fff; height: 400px; width: 400px;">test2 {{modelContent.toggleModal}}</div>
        <button @click="modelContent.setToggleModal(false)">click me</button>
      </template>
    </PopoverModal>
  </div>
</template>

<script>
import PopoverModal from './PopoverModal'
export default {
  components: {PopoverModal},
  name: 'HelloWorld',
  data () {
    return {
    }
  }
}
</script>
<template>
  <div>
    <slot name="toggleButton"></slot>
    <slot name="modalContent" :toggleModal="showSelector" :setToggleModal="setShowSelector"></slot>
  </div>
</template>

<script>
export default {
  data () {
    return {
      showSelector: true
    }
  },
  methods: {
    setShowSelector(showSelector) {
      this.showSelector = showSelector;
    },
  }
}
</script>
-----------------------
<template>
  <div class="hello">
    <PopoverModal>
      <template #toggleButton>
        <button>A</button>
      </template>
      <template #modalContent="modelContent">
        <div style="color: #fff; height: 400px; width: 400px;">test2 {{modelContent.toggleModal}}</div>
        <button @click="modelContent.setToggleModal(false)">click me</button>
      </template>
    </PopoverModal>
  </div>
</template>

<script>
import PopoverModal from './PopoverModal'
export default {
  components: {PopoverModal},
  name: 'HelloWorld',
  data () {
    return {
    }
  }
}
</script>
<template>
  <div>
    <slot name="toggleButton"></slot>
    <slot name="modalContent" :toggleModal="showSelector" :setToggleModal="setShowSelector"></slot>
  </div>
</template>

<script>
export default {
  data () {
    return {
      showSelector: true
    }
  },
  methods: {
    setShowSelector(showSelector) {
      this.showSelector = showSelector;
    },
  }
}
</script>

COMMUNITY DISCUSSIONS

Top Trending Discussions on ToggleButton
  • How to style ToggleButon in material-ui
  • Run Storyboard inside DataTemplate when an event occurs
  • RadioButton with custom image and text change at runtime
  • Get the value from input when button is clicked
  • How to add sub-options under options in select dropdown menu in react?
  • showing record text with red color when click stop button
  • In backdraftjs can you trigger a component re-render from within the component?
  • word-wrap not working in react-bootstrap navbar
  • Сombobox closes when I try to click on the elements inside WPF
  • How to use v-model on a slot in vue 3?
Top Trending Discussions on ToggleButton

QUESTION

How to style ToggleButon in material-ui

Asked 2021-Jun-11 at 03:57

I'm trying to style ToggleButton to override default color when it's selected. But it doesn't work.

const useStyles = makeStyles((theme) => ({   
  toggleButtonSelected: {
      "background-color": "red"
  }
}))

.......
<ToggleButtonGroup exclusive>
    <ToggleButton
        classes={{ selected: classes.toggleButtonSelected }}
        value="a" >
        Button A
    </ToggleButton>
    <ToggleButton
        classes={{ selected: classes.toggleButtonSelected }}
        value="b">
        Button B
    </ToggleButton>
</ToggleButtonGroup>

ANSWER

Answered 2021-Jun-11 at 03:57

Solution

Try to change your makeStyles styling to the following:

const useStyles = makeStyles((theme) => ({
  toggleButtonSelected: {
    "&.MuiToggleButton-root": {
      "background-color": "red"
    }
  }
}));

Edit on Code Sandbox

Explanation

Original specificity

Your original makeStyles styling is not working because it generates a CSS rule with selector of .makeStyles-toggleButtonSelected-1 (circled in red in the above screenshot), which is overridden by another rule with higher specificity.

With our new makeStyles styling, it generates a CSS rule with the selector having a higher selectivity than your original styling (circled in red in below). This new styling can successfully override the default styling.

New specificity

Source https://stackoverflow.com/questions/67930752

QUESTION

Run Storyboard inside DataTemplate when an event occurs

Asked 2021-Jun-09 at 14:33

I have a ToggleButton and an ItemsControl. The ItemsControl's items have a DataTemplate. How can I animate each of ItemsControl's items, when ToggleButton's check state is changed?

The code

In the following code, you can see when the user clicks on the ToggleButton, the chevron rotates. I want the items in the ItemsControl to animate as well. I added a Storyboard with the key "ItemAnimation". I think somehow it should be triggered when the user clicks on the button.

<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <DataTemplate x:Key="ShortcutButton">
            <DataTemplate.Resources>
                <Storyboard x:Key="ItemAnimation" AutoReverse="False">
                    <DoubleAnimation Storyboard.TargetName="Trans" Storyboard.TargetProperty="Y" Duration="0:0:0.25" From="-100" To="0" EasingFunction="{StaticResource AnimationEase}" />
                </Storyboard>
            </DataTemplate.Resources>
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.RenderTransform>
                    <TranslateTransform x:Name="Trans"/>
                </Border.RenderTransform>
                <TextBlock Text="{Binding Name}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png" />
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="True" Command="{Binding ClickCommand}">
                    <Image x:Name="chevron" Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                    <ToggleButton.Triggers>
                        <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="ToggleButton.Checked">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="chevron" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                        <DoubleAnimation.EasingFunction>
                                            <PowerEase EasingMode="EaseIn" />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ToggleButton.Triggers>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl ItemsSource="{Binding Shortcuts}"
                      RenderTransform="{Binding Transform}"
                      ItemTemplate="{StaticResource ShortcutButton}"/>
    </StackPanel>
</Window>

Update

I want the icons to move from behind the logo to their positions. Meaning the first one would move 100 pixels, the second 200, the third 300, and so on. Here's what I want in a picture: animation

ANSWER

Answered 2021-Jun-08 at 14:11

Using EventTrigger across control (and data template) boundaries can be somewhat limiting. Data binding to the rescue!

The trimmed ViewModel.

using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace WinClient
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public MainViewModel()
        {
            IsChecked = true;
        }

        private bool _isChecked;
        public bool IsChecked
        {
            set
            {
                _isChecked = value;
                OnPropertyChanged();
            }
            get
            {
                return _isChecked;
            }
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion INotifyPropertyChanged
    }
}

The View.

<Window x:Class="WinClient.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WinClient"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="MainWindow" Height="800" Width="450">
    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <DataTemplate x:Key="ShortcutButton">
            <Border Width="100" Height="100" Background="White" CornerRadius="50" x:Name="ContainerBorder">
                <Border.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DataContext.IsChecked, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="False">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard AutoReverse="False">
                                            <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="0:0:0.25" From="-100" To="0" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
                <Border.RenderTransform>
                    <TranslateTransform/>
                </Border.RenderTransform>
                <TextBlock Text="{Binding}" FontSize="60" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>
    </Window.Resources>
    <StackPanel VerticalAlignment="Top" Margin="50">
        <Border Width="150" Height="150" CornerRadius="75" Background="White" BorderBrush="#FFC12121">
            <Grid>
                <Image Source="Resources/logo.png" />
                <ToggleButton Width="40" Height="40" VerticalAlignment="Bottom" IsChecked="{Binding IsChecked}">
                    <Image Source="Resources/chevron-down.png" Width="32" Height="32">
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsChecked}" Value="False">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="0" To="180" Duration="0:0:0.3">
                                                        <DoubleAnimation.EasingFunction>
                                                            <PowerEase EasingMode="EaseIn" />
                                                        </DoubleAnimation.EasingFunction>
                                                    </DoubleAnimation>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                        <DataTrigger.ExitActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" From="180" To="0" Duration="0:0:0.3">
                                                        <DoubleAnimation.EasingFunction>
                                                            <PowerEase EasingMode="EaseIn" />
                                                        </DoubleAnimation.EasingFunction>
                                                    </DoubleAnimation>                                                
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.ExitActions>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                        <Image.RenderTransform>
                            <RotateTransform CenterX="16" CenterY="16"/>
                        </Image.RenderTransform>
                    </Image>
                </ToggleButton>
            </Grid>
        </Border>
        <ItemsControl ItemTemplate="{StaticResource ShortcutButton}">
            <ItemsControl.Items>
                <sys:Int32>1</sys:Int32>
                <sys:Int32>2</sys:Int32>
                <sys:Int32>3</sys:Int32>
            </ItemsControl.Items>
        </ItemsControl>
    </StackPanel>
</Window>

Source https://stackoverflow.com/questions/67858348

QUESTION

RadioButton with custom image and text change at runtime

Asked 2021-Jun-09 at 07:06

I have a custom RadioButton style with an Image and 2 TextBlocks.

<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}" >
    
    <Setter Property="Background" Value="#32353B" />
    <Setter Property="Margin" Value="10,5"/>
    <Setter Property="Height" Value="45" />
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="Padding" Value="1" />
    <Setter Property="HorizontalAlignment" Value="Stretch"/>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToggleButton}">
                <StackPanel>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            Background="{TemplateBinding Background}">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0">
                            <ContentPresenter HorizontalAlignment="Left"                  
                                          VerticalAlignment="Center"/>

                            <Image Source="{TemplateBinding Button.Tag}"  HorizontalAlignment="Left" Stretch="Uniform" Width="45" IsEnabled="True" />

                            <StackPanel Margin="2">
                                <TextBlock Foreground="#DCDDDE"  FontSize="18" FontFamily="Arial">Strona</TextBlock>
                                <TextBlock Foreground="#52555C"  FontSize="12" FontFamily="Arial"> Login</TextBlock>
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </StackPanel>

            </ControlTemplate>

        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsChecked" Value="True">
            <Setter Property="Background" Value="#282B2E"/>
        </Trigger>
  
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background">
                <Setter.Value>
                    <SolidColorBrush Color="#FF282B2E" Opacity="0.5"/>
                </Setter.Value>
            </Setter>
        </Trigger>
      
    </Style.Triggers>
</Style>

When I create a new button at runtime, setting the Style and I want to change the Image and the text for every single RadioButton. Right now I am thinking about using a Tag for that.

RadioButton radioButton = new RadioButton();

 radioButton.GroupName = "Side";

 radioButton.Style = (Style)Resources["ToggleButton_Chose"];

 radioButton.Tag = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));

Is there any other method to set this? I will have around 100 of the RadioButtons and any of them should get different images and texts.

ANSWER

Answered 2021-Jun-09 at 06:59

Custom Control

If you want to create a ToggleButton that requires additional (bindable) properties, you could create a custom control with dependency properties for the image and texts based on the ToggleButton type. Create a new type AdvancedToggleButton that derives from ToggleButton.

public class AdvancedToggleButton : ToggleButton
{
   static AdvancedToggleButton()
   {
      DefaultStyleKeyProperty.OverrideMetadata(typeof(AdvancedToggleButton), new FrameworkPropertyMetadata(typeof(AdvancedToggleButton)));
   }

   public ImageSource ImageSource
   {
      get => (ImageSource) GetValue(ImageSourceProperty);
      set => SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
      nameof(ImageSource), typeof(ImageSource), typeof(AdvancedToggleButton));

   public string FirstText
   {
      get => (string) GetValue(FirstTextProperty);
      set => SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.Register(
      nameof(FirstText), typeof(string), typeof(AdvancedToggleButton));

   public string SecondText
   {
      get => (string) GetValue(SecondTextProperty);
      set => SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.Register(
      nameof(SecondText), typeof(string), typeof(AdvancedToggleButton));
}

Then you can create a default implicit style (by omitting the x:Key) in your application resources or another resource dictionary in scope, so the style is applied automatically.

<Style TargetType="{x:Type local:AdvancedToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:AdvancedToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{TemplateBinding ImageSource}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding FirstText}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{TemplateBinding SecondText}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>

Note, that I removed the duplicate setter for HorizontalAlignment. The Image binds its Source to the ImageSource property and the TextBlocks bind to FirstText and SecondText respectively. You can either define the AdvancedToggleButton in XAML or code.

<local:AdvancedToggleButton ImageSource="\Resources/Check.jpg"
                            FirstText="Strona"
                            SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
radioButton.ImageSource = new BitmapImage(new Uri("https://www.google.com/favicon.ico"));
radioButton.FirstText = "Strona";
radioButton.SecondText = "Login"

Useful resources on custom controls:

Attached Properties

An alternative without creating a custom control is to create a set of attached properties.

public static class ToggleButtonProperties
{
   public static ImageSource GetImageSource(DependencyObject dependencyObject)
   {
      return (ImageSource) dependencyObject.GetValue(ImageSourceProperty);
   }

   public static void SetImageSource(DependencyObject dependencyObject, ImageSource value)
   {
      dependencyObject.SetValue(ImageSourceProperty, value);
   }

   public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.RegisterAttached(
      "ImageSource", typeof(ImageSource), typeof(ToggleButtonProperties));

   public static string GetFirstText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(FirstTextProperty);
   }

   public static void SetFirstText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(FirstTextProperty, value);
   }

   public static readonly DependencyProperty FirstTextProperty = DependencyProperty.RegisterAttached(
      "FirstText", typeof(string), typeof(ToggleButtonProperties));

   public static string GetSecondText(DependencyObject dependencyObject)
   {
      return (string) dependencyObject.GetValue(SecondTextProperty);
   }

   public static void SetSecondText(DependencyObject dependencyObject, string value)
   {
      dependencyObject.SetValue(SecondTextProperty, value);
   }

   public static readonly DependencyProperty SecondTextProperty = DependencyProperty.RegisterAttached(
      "SecondText", typeof(string), typeof(ToggleButtonProperties));
}

These properties can be bound in the control template using parentheses, which is the binding syntax for attached properties and RelativeSource to the parent ToggleButton.

<Style x:Key="ToggleButton_Chose" TargetType="{x:Type ToggleButton}">

   <Setter Property="Background"
           Value="#32353B" />
   <Setter Property="Margin"
           Value="10,5" />
   <Setter Property="Height"
           Value="45" />
   <Setter Property="BorderThickness"
           Value="0" />
   <Setter Property="Padding"
           Value="1" />
   <Setter Property="HorizontalAlignment"
           Value="Stretch" />

   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel>
               <Border BorderBrush="{TemplateBinding BorderBrush}"
                       Background="{TemplateBinding Background}">
                  <StackPanel Orientation="Horizontal"
                              HorizontalAlignment="Left"
                              Margin="0">
                     <ContentPresenter HorizontalAlignment="Left"
                                       VerticalAlignment="Center" />

                     <Image Source="{Binding (local:ToggleButtonProperties.ImageSource), RelativeSource={RelativeSource TemplatedParent}}"
                            HorizontalAlignment="Left"
                            Stretch="Uniform"
                            Width="45"
                            IsEnabled="True" />

                     <StackPanel Margin="2">
                        <TextBlock Foreground="#DCDDDE"
                                   FontSize="18"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.FirstText), RelativeSource={RelativeSource TemplatedParent}}"/>
                        <TextBlock Foreground="#52555C"
                                   FontSize="12"
                                   FontFamily="Arial"
                                   Text="{Binding (local:ToggleButtonProperties.SecondText), RelativeSource={RelativeSource TemplatedParent}}"/>
                     </StackPanel>
                  </StackPanel>
               </Border>
            </StackPanel>

         </ControlTemplate>

      </Setter.Value>
   </Setter>
   <Style.Triggers>
      <Trigger Property="IsChecked"
               Value="True">
         <Setter Property="Background"
                 Value="#282B2E" />
      </Trigger>

      <Trigger Property="IsMouseOver"
               Value="True">
         <Setter Property="Background">
            <Setter.Value>
               <SolidColorBrush Color="#FF282B2E"
                                Opacity="0.5" />
            </Setter.Value>
         </Setter>
      </Trigger>

   </Style.Triggers>
</Style>

Assigning or binding the attached properties is done via the static class.

<ToggleButton Style="{StaticResource ToggleButton_Chose}"
              local:ToggleButtonProperties.ImageSource="\Resources/Check.jpg"
              local:ToggleButtonProperties.FirstText="Strona"
              local:ToggleButtonProperties.SecondText="Login"/>
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "Side";
ToggleButtonProperties.SetImageSource(radioButton, new BitmapImage(new Uri("https://www.google.com/favicon.ico")));
ToggleButtonProperties.SetFirstText(radioButton, "Strona");
ToggleButtonProperties.SetSecondText(radioButton, "Login");

Useful resources on attached properties:

Source https://stackoverflow.com/questions/67896486

QUESTION

Get the value from input when button is clicked

Asked 2021-Jun-08 at 18:38

Having this code snippet:

const MyComponent = ({ e }) => {
  const toggleButton = (e) => {
    console.log('eee: ', e.target.value);
  };
  return (
    <div>
      <div>
        <input className='input-search' type='text' placeholder='search' />
        <Button onClick={(e) => toggleButton(e)}>reset</Button>
      </div>
    </div>
  );
};

I was expecting to see in the log the value from input but it is undefined. Any thoughts?

ANSWER

Answered 2021-Jun-08 at 18:38

e.target is the button which has no value attribute. You should be storing the input value in state with a onChange event. Make sure that the input's value attribute reflects the state, and use useEffect to log the changes to the console.

const {useState, useEffect} = React;

function Example() {

  const [input, setInput] = useState('');

  useEffect(() => {
    console.log(`State: ${input}`);
  }, [input])

  function handleClick() {
    setInput('');
  }

  function handleInput(e) {
    const { target: { value } } = e;
    setInput(value);
  }

  return (
    <div>
      <div>
        <input onChange={handleInput} type="text" placeholder="search" value={input} />
        <button onClick={handleClick}>reset</button>
      </div>
    </div>
  );

};

// Render it
ReactDOM.render(
  <Example />,
  document.getElementById("react")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="react"></div>

Source https://stackoverflow.com/questions/67892214

QUESTION

How to add sub-options under options in select dropdown menu in react?

Asked 2021-Jun-06 at 15:40

I am implementing a react app in which there is a dropdown menu with different options that are fetched from a dummy backend api using json-server I am able to add options but I need to add sub-options that are also fetched from api.

Here's my db.json Api structure:

{  
  "groups":[  
     {  
        "key":"version",
        "apis":["system_info","admin"]
     },
     {  
        "key":"admin",
        "apis":["patients","doctors"]
     },
    
  ]
}

In the above json respsonse keys are the options and all the strings under apis are to be sub-options.

Here's my Dropdown menu implementation:

import React from "react";

export default class ApiDropDown extends React.Component {
  constructor() {
    super();
    this.state = {
      options: []
    };
  }

  componentDidMount() {
    this.fetchOptions();
  }

  fetchOptions() {
    fetch("http://localhost:5000/groups")
      .then((res) => {
        return res.json();
      })
      .then((json) => {
        console.log(json);
        this.setState({ options: json });
      });
  }
  render() {
    return (
      <div >
        <select className="togglebutton" >
        <option selected disabled>Choose here</option>
          {this.state.options.map((option, key) => (
           
           <option key={key}>{option["key"]}</option>
           
           
          ))}
        </select>
      </div>
    );
  }
}

Api Response:

0: {key: "version", apis: Array(2)}
1: {key: "admin", apis: Array(2)}

This above dropdown is working for options but I need to implement sub-options. Any idea how i can implement this?

Thanks!

ANSWER

Answered 2021-Jun-06 at 15:40

You can just fetch the suboption as you didn't for options. And use the below code for the sub option.

render() {
    return (
     <div >
      <select className="togglebutton" >
      <option selected disabled>Choose here</option>
        {this.state.options.map((option, key) => (
       
        <option key={key}>{option["key"]}</option>
         
         <optgroup label={option["key"]}>
            {this.state.subOptions.map((subOption, key) => (
              <option>{subOption.key}</option>
            ))}
             // OR

           {this.state.option["key"].subOptions.map((subOpt,i) => (
              <option>{subOpt.i}</option>
            ))}
           
         </optgroup>
   
       ))}
     </select>
   </div>
 );
}    

Source https://stackoverflow.com/questions/67856308

QUESTION

showing record text with red color when click stop button

Asked 2021-Jun-06 at 01:55

I have a question regarding html, css, javascript.

I've made a game in which numbers must be pressed in order.

And I have to show the record time with red color when I click the stop button in the middle of the game. like this... enter image description here

Also I've got hints.

  1. Use the code
newP.className = "stopped";
  1. CSS selector by class name
  2. Create div(division): Game success, Game stop

Here's my full code.

var answer = 0;

function start() {
  startTime = new Date().getTime();
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Stop";
  toggleButton.onclick = stop;

  init();

  timer = setInterval(function() {
    now = new Date().getTime();
    seconds = now - startTime;
    document.getElementById("time").innerHTML = displayTime(seconds);
  }, 60);
}

function stop() {
  clearInterval(timer);
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Start";
  toggleButton.onclick = start;
}

function btnClick(num) {
  btns = document.getElementsByClassName("btn");
  if (num == answer) { 
    answer = answer+1;
    btns[num].disabled = true;
    if (num == 8) { 
      stop();
      score = document.getElementById("time").innerHTML;
      newP = document.createElement("p");
      newP.appendChild(document.createTextNode(score));
      document.getElementById("score_board").appendChild(newP);
    }
  } else { 
    init();
  }
}

function init() {
  answer = 0;

  btns = document.getElementsByClassName("btn");
  for (let index=0; index<btns.length; index++) {
    btns[index].disabled = false;
    btns[index].innerHTML = index;
  }
}

function displayTime (seconds) {
  m = String(Math.floor(seconds / 1000 / 60));
  s = String(Math.floor((seconds / 1000) % 60));
  ms = String(Math.floor(seconds % 100));
  return m.padStart(2, '0') + ":" + s.padStart(2, '0') + ":" + ms.padStart(2, '0');
};
.btn {
  width:60px;
  height:60px;
  font-size:18px;
  margin:2px;
} /*select by class */

#toggle_button {
  width:120px;
  background-color:#000;
  color:#fff;
  height:24px;
  border:none;
}

#time {
  font-size:20px;
  font-weight:bold;
} /*select by id */

img {
  width:100px;
} /*select by html elemnt */
<center>
  <p id="time">00:00:00</p>
  <button id="toggle_button" onclick="start()">Start</button>
  <br /><br />

  <button id="button_1" class="btn" onclick="btnClick(0)" disabled>?</button>
  <button id="button_2" class="btn" onclick="btnClick(1)" disabled>?</button>
  <button id="button_3" class="btn" onclick="btnClick(2)" disabled>?</button><br />
  <button id="button_4" class="btn" onclick="btnClick(3)" disabled>?</button>
  <button id="button_5" class="btn" onclick="btnClick(4)" disabled>?</button>
  <button id="button_6" class="btn" onclick="btnClick(5)" disabled>?</button><br />
  <button id="button_7" class="btn" onclick="btnClick(6)" disabled>?</button>
  <button id="button_8" class="btn" onclick="btnClick(7)" disabled>?</button>
  <button id="button_9" class="btn" onclick="btnClick(8)" disabled>?</button>

  <div id="score_board">
    <p><strong>Score Board</strong><p>
  </div>
</center>

Sorry for bad English since I'm not a native speaker. Thank you so much...!

ANSWER

Answered 2021-Jun-05 at 10:06

Following piece of code is the change in the stop function. If stop function has a parameter the color is gonna be red. When user press the stop button, html send press action as a parameter. But when the game is completed the function is called without parameter. Thus you could show score as red when user break the game and black when user complete the game.

const scoreBoard = document.querySelector('#score_board');
const score = document.getElementById("time").innerHTML;
const scoreEl = document.createElement('p');
if(c) scoreEl.style.color = 'red';
const node = document.createTextNode(score);
scoreEl.appendChild(node);
scoreBoard.appendChild(scoreEl);

Here is the example:

var answer = 0;

function start() {
  startTime = new Date().getTime();
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Stop";
  toggleButton.onclick = stop;

  init();

  timer = setInterval(function() {
    now = new Date().getTime();
    seconds = now - startTime;
    document.getElementById("time").innerHTML = displayTime(seconds);
  }, 60);
}

function stop(c) {
  clearInterval(timer);
  const scoreBoard = document.querySelector('#score_board');
  const score = document.getElementById("time").innerHTML;
  const scoreEl = document.createElement('p');
  if(c) scoreEl.style.color = 'red';
  const node = document.createTextNode(score);
  scoreEl.appendChild(node);
  scoreBoard.appendChild(scoreEl);
  toggleButton = document.getElementById("toggle_button");
  toggleButton.innerHTML = "Start";
  toggleButton.onclick = start;
}

function btnClick(num) {
  btns = document.getElementsByClassName("btn");
  if (num == answer) { 
    answer = answer+1;
    btns[num].disabled = true;
    if (num == 8) { 
      stop();
    }
  } else { 
    init();
  }
}

function init() {
  answer = 0;

  btns = document.getElementsByClassName("btn");
  for (let index=0; index<btns.length; index++) {
    btns[index].disabled = false;
    btns[index].innerHTML = index;
  }
}

function displayTime (seconds) {
  m = String(Math.floor(seconds / 1000 / 60));
  s = String(Math.floor((seconds / 1000) % 60));
  ms = String(Math.floor(seconds % 100));
  return m.padStart(2, '0') + ":" + s.padStart(2, '0') + ":" + ms.padStart(2, '0');
};
.btn {
  width:60px;
  height:60px;
  font-size:18px;
  margin:2px;
} /*select by class */

#toggle_button {
  width:120px;
  background-color:#000;
  color:#fff;
  height:24px;
  border:none;
}

#time {
  font-size:20px;
  font-weight:bold;
} /*select by id */

img {
  width:100px;
} /*select by html elemnt */
<center>
  <p id="time">00:00:00</p>
  <button id="toggle_button" onclick="start()">Start</button>
  <br /><br />

  <button id="button_1" class="btn" onclick="btnClick(0)" disabled>?</button>
  <button id="button_2" class="btn" onclick="btnClick(1)" disabled>?</button>
  <button id="button_3" class="btn" onclick="btnClick(2)" disabled>?</button><br />
  <button id="button_4" class="btn" onclick="btnClick(3)" disabled>?</button>
  <button id="button_5" class="btn" onclick="btnClick(4)" disabled>?</button>
  <button id="button_6" class="btn" onclick="btnClick(5)" disabled>?</button><br />
  <button id="button_7" class="btn" onclick="btnClick(6)" disabled>?</button>
  <button id="button_8" class="btn" onclick="btnClick(7)" disabled>?</button>
  <button id="button_9" class="btn" onclick="btnClick(8)" disabled>?</button>

  <div id="score_board">
    <p><strong>Score Board</strong><p>
  </div>
</center>

Source https://stackoverflow.com/questions/67847514

QUESTION

In backdraftjs can you trigger a component re-render from within the component?

Asked 2021-Jun-05 at 13:41

Here is a backdraftjs component that does not work:

class ClickButton extends Component {
    constructor(kwargs) {
        super(kwargs);
        this.clicked = false;
    }
    
    toggleButton() {
        this.clicked = !this.clicked;
    }
    
    bdElements() {
        return e.div(
            {
                className: this.clicked ? 'clicked' : '',
                bdAdvise: {click: 'toggleButton'}
            },
            'Click Me'
        );
    }
}

...that is, the component doesn't re-render with the "clicked" class after you click it (and of course it doesn't).

I could change it to use watchables, and then trigger the change from outside:

class ClickButton extends Component.withWatchables('isClicked') {    
    bdElements() {
        return e.div(
            {
                bdReflect: {
                    className: ['isClicked', c => c ? 'clicked' : '']
                },
                bdAdvise: {click: this.kwargs.toggleClick}
            },
            'Click Me'
        );
    }
}

But is there some way to keep this all internal to the component? Something like ReactJS component state, where you make a change and it causes the component to re-render and reflect the new state?

ANSWER

Answered 2021-Jun-05 at 13:41

Beginning at the end with the key question:

But is there some way to keep this all internal to the component? Something like ReactJS component state, where you make a change and it causes the component to re-render and reflect the new state?

A ReactJS component state is an aggregate state: it almost-always controls multiple facets of a component (always, with non-trivial components). And mutating one of those facets implies mutating the aggregate state object, which in turn causes a "re-render" of the entire component. You can certainly construct backdraft components to follow this model, but backdraft was not designed to follow such a model (for rational engineering objectives discussed in other forums).

Turning now to the op's particular example, notice that the first solution exposes the property clicked on the public interface of instances of ClickButton. So, clearly, this example does not "keep this all internal to the component".

I think the real question is, "what is the public interface that ClickButton is offering?" I'm guessing op wants:

  1. a button
  2. that has a public read/write boolean property clicked
  3. that toggles its clicked property each time the button is clicked
  4. that sets its DOM class to 'clicked' when the clicked property changes from false to true and conversely

Here is such a component:

class ClickButton extends Component.withWatchables('clicked') {
    bdElements() {
        return e.button(
            {
                bdReflectClass: ['clicked', value=>(value ? 'clicked' : '')],
                bdAdvise_click: e=>(this.clicked = !this.clicked)
            },
            'Click Me'
        );
    }
}

Here's an example of the above code, live in a pen: https://codepen.io/rcgill/pen/eYvrNeB

Perhaps I've failed to understand the thrust of the question and the op is looking for ways to either implement (1) private data, or (2) state mutation implies complete re-render. There are canonical solutions to the former; you can do the latter with backdraft, but if that's the model you prefer, it's probably better to use ReactJS.

Source https://stackoverflow.com/questions/67845280

QUESTION

word-wrap not working in react-bootstrap navbar

Asked 2021-Jun-03 at 04:33

I am trying to make a responsive navbar in react-bootstrap. Once I get down to h4, i want to start normal word wrapping, but no matter what, the h4 text goes outside the div container on the right when I try to test it's responsiveness in chrome. The nav-bar hovers above a dynamic map which is why the z-value is 2. Here is the js file:

import React from 'react';
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import { Navbar, Nav, NavItem, NavDropdown, ToggleButton, ToggleButtonGroup } from 'react-bootstrap';

export default function Routing(props) {
   return (
        <>
            <Router>
                <Navbar collapseOnSelect className="navbar">
                    <div className="h-box">
                        <Navbar.Brand>
                            <h4>Portland Watershed Data Dashboard</h4>
                        </Navbar.Brand>
                    </div>

                    <Navbar.Collapse id="basic-navbar-nav">
                        <Nav className="ml-auto align-items-center">
                            <Nav.Link>
                                <Link to="/"><h5 className="tiny link">Home</h5></Link>
                            </Nav.Link>
                            <Nav.Link>
                                <Link to="/page"><h5 className="tiny link">Gradient</h5></Link>
                            </Nav.Link>
                        </Nav>
                    </Navbar.Collapse>
                </Navbar>
                 <Switch>
                        <>
                            <Route exact path="/">
                                <Home />
                            </Route>
                            <Route exact path="/page">
                                <Page />
                            </Route>
                        </>
                    </Switch>
                </Map>
            </Router>

        </>
    )

And here is the css for these elements, I have removed all the text color, background color, and shadowing for readability.

body {
  margin: 0px;
  padding: 0px;
}
.header {
  height: 45px;
  position: fixed;
  top: 0;
}
.navbar {
  left: 0;
  position: fixed;
  top: 0;
  z-index: 2; 
  width: 100%;
  display: block;
}

.h-box {
  border: solid black;
  padding-top: 0.5vh;
  padding-bottom: 0.5vh;
  padding-left: 2vh;
  padding-right: 1vh;
  text-align: center;
}
.tiny, .h-box h4 {
     display: block;
   }
.link {
  margin-right: 2vh;
}

ANSWER

Answered 2021-Jun-03 at 04:33

add this className to h4:

<h4 className="text-wrap">Example Headline Here</h4>

should take care of your problem

Source https://stackoverflow.com/questions/67804758

QUESTION

Сombobox closes when I try to click on the elements inside WPF

Asked 2021-Jun-01 at 14:44

The combo box closes when I try to move the slider. I tried different methods but nothing helps, in particular putting all the content inside the ToggleButton

<ComboBox HorizontalAlignment="Right" Background="Transparent" BorderBrush="Transparent" Width="20" Height="20" Style="{DynamicResource ComboBoxForSound}">
                            <ComboBoxItem  Background="Transparent" Style="{DynamicResource ComboBoxItemStyle1}">
                                <Grid Width="208" Height="108">
                                    <Border CornerRadius="22" BorderThickness="1" BorderBrush="Black">
                                        <Border.Background>
                                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                                <GradientStop Color="#2d2d2e" Offset="0" />
                                                <GradientStop Color="#151517" Offset="1" />
                                            </LinearGradientBrush>
                                        </Border.Background>
                                    </Border>
                                    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="28,20,0,0" Height="64" Width="150">
                                        <TextBlock Text="Громкость" FontSize="14" Foreground="Orange" FontFamily="{DynamicResource MontserratAlternates}" Margin="5,0,0,0" />
                                        <Slider Margin="0,14,0,0" Name="SoundSlider" TickFrequency="1" IsSelectionRangeEnabled="True" Minimum="0" Maximum="9" SelectionStart="0" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource SliderStyle1}" ValueChanged="Slider_ValueChanged_1" />
                                    </StackPanel>
                                </Grid>
                            </ComboBoxItem>
                        </ComboBox>

ANSWER

Answered 2021-Jun-01 at 14:44
  1. Do you have only one item in your ComboBox? The built-in behavior of a ComboBox after an item is selected is to collapse. Selecting an element is the transfer of focus, including to any of its child elements. As soon as you click on the Slider it receives focus, the item is selected and the CombobBox collapses.

  2. In general, it looks like some kind of nonsense, complete . ComboBox is for selecting items from a list of items that you don't even have. If you just need to hide-reveal a set of elements, then use Expander.

  3. If you need something different, then explain normally and in detail what you want to implement.

The answer is supplemented by an explanation for additional details in the question:

I'm trying to make a context menu where I can move the slider and so that it doesn't close, the expander doesn't fit because I don't need to move the elements of my window, but open on top of it

In WPF, elements are selected based on their behavior logic. And their visual appearance is set by styles and/or templates.
ComboBox behavior: when you click on it, expand the list, when you click on an item in the list, select it and collapse the list.

Do you need this behavior?
Not.
Hence you don't need a ComboBox.

Most likely, judging by your description, you need a combination of ToggleButton and Popup.

A simple example:

<Window x:Class="SliderInPopup.SliderInPopupWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SliderInPopup"
        mc:Ignorable="d"
        Title="SliderInPopupWindow" Height="450" Width="800">
    <Grid>
        <ToggleButton x:Name="toggleButton" VerticalAlignment="Top" HorizontalAlignment="Left" Content="Click Me"/>
        <Popup x:Name="popup1" StaysOpen="False"
               Placement="Mouse" AllowsTransparency="True"
               IsOpen="{Binding IsChecked, ElementName=toggleButton}"  >
            <Grid Width="208" Height="108">
                <Border CornerRadius="22" BorderThickness="1" BorderBrush="Black">
                    <Border.Background>
                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <GradientStop Color="#2d2d2e" Offset="0" />
                            <GradientStop Color="#151517" Offset="1" />
                        </LinearGradientBrush>
                    </Border.Background>
                </Border>
                <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="28,20,0,0" Height="64" Width="150">
                    <TextBlock Text="Громкость" FontSize="14" Foreground="Orange" Margin="5,0,0,0" />
                    <Slider Margin="0,14,0,0" Name="SoundSlider" TickFrequency="1" IsSelectionRangeEnabled="True" Minimum="0" Maximum="9" SelectionStart="0" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </StackPanel>
            </Grid>
        </Popup>
    </Grid>
</Window>

Source https://stackoverflow.com/questions/67780372

QUESTION

How to use v-model on a slot in vue 3?

Asked 2021-Jun-01 at 03:31

I am trying to find a way to use a model component I made but with the ability to close the model from one of the slots.

I can pass data to the slot but not with v-model and dont believe I can change the slot prop to close the model open state

https://v3.vuejs.org/guide/component-slots.html#scoped-slots

this is my popover in use

<PopoverModal>
    <template #toggleButton>
      <button>A</button>
    </template>
    <template #modalContent="{ toggleModal }">
      <div style="color: #fff; height: 400px; width: 400px;">test2 {{toggleModal}}</div>
      <button @click="toggleModal = false">click me</button>
    </template>
  </PopoverModal>

within the popover component I am trying to be able to send the state var

<slot name="modalContent" :toggleModal="showSelector"></slot>

I'm guessing the answer is its not possible and to find another way but if anyone knows that would be great thanks

ANSWER

Answered 2021-Jun-01 at 03:31

You can't change PopoverModal data directly using template, but you can bind some setter methods.

Some example code:

HelloWorld.vue

<template>
  <div class="hello">
    <PopoverModal>
      <template #toggleButton>
        <button>A</button>
      </template>
      <template #modalContent="modelContent">
        <div style="color: #fff; height: 400px; width: 400px;">test2 {{modelContent.toggleModal}}</div>
        <button @click="modelContent.setToggleModal(false)">click me</button>
      </template>
    </PopoverModal>
  </div>
</template>

<script>
import PopoverModal from './PopoverModal'
export default {
  components: {PopoverModal},
  name: 'HelloWorld',
  data () {
    return {
    }
  }
}
</script>

PopoverModal.vue

<template>
  <div>
    <slot name="toggleButton"></slot>
    <slot name="modalContent" :toggleModal="showSelector" :setToggleModal="setShowSelector"></slot>
  </div>
</template>

<script>
export default {
  data () {
    return {
      showSelector: true
    }
  },
  methods: {
    setShowSelector(showSelector) {
      this.showSelector = showSelector;
    },
  }
}
</script>

Source https://stackoverflow.com/questions/67782165

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

VULNERABILITIES

No vulnerabilities reported

INSTALL ToggleButton

You can use ToggleButton like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the ToggleButton component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

SUPPORT

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Implement ToggleButton faster with kandi.

  • Use the support, quality, security, license, reuse scores and reviewed functions to confirm the fit for your project.
  • Use the, Q & A, Installation and Support guides to implement faster.

Discover Millions of Libraries and
Pre-built Use Cases on kandi