Add checked event listener to RadioButton : RadioButton « Windows Presentation Foundation « C# / CSharp Tutorial






using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

    public class MainClass : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new MainClass());
        }
        public MainClass()
        {
            SizeToContent = SizeToContent.WidthAndHeight;

            GroupBox group = new GroupBox();
            group.Header = "Window Style";
            group.Margin = new Thickness(96);
            group.Padding = new Thickness(5);
            Content = group;

            StackPanel stack = new StackPanel();
            group.Content = stack;

            RadioButton radio = new RadioButton();
            radio.Content = "No border or caption";
            radio.Tag = WindowStyle.None;
            radio.Margin = new Thickness(5);
            stack.Children.Add(radio);

            radio = new RadioButton();
            radio.Content = "Single-border window";
            radio.Tag = WindowStyle.SingleBorderWindow;
            radio.Margin = new Thickness(5);
            radio.IsChecked = (WindowStyle.SingleBorderWindow == WindowStyle);
            stack.Children.Add(radio);

            AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(RadioOnChecked));
        }
        void RadioOnChecked(object sender, RoutedEventArgs args)
        {
            RadioButton radio = args.Source as RadioButton;
            WindowStyle = (WindowStyle)radio.Tag;
        }
    }








24.21.RadioButton
24.21.1.Checked RadioButtonChecked RadioButton
24.21.2.Use StackPanel to Hold RadioButtonsUse StackPanel to Hold RadioButtons
24.21.3.Circled Radio ButtonsCircled Radio Buttons
24.21.4.Color animate based on Radio Button Click eventColor animate based on Radio Button Click event
24.21.5.Radio Button GroupsRadio Button Groups
24.21.6.Set RadioButton to check stateSet RadioButton to check state
24.21.7.Image RadioButtonImage RadioButton
24.21.8.Add checked event listener to RadioButton
24.21.9.Assign value to RadioButton tag