본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

라디오버튼 ( Radio Button / Select / 설문조사 / XAML / 디자인 )

728x90
반응형


라디오버튼 예제 ( Radio Button / Select Button / 설문조사 / XAML / 디자인 )


필요해서 찾았다가 기왕 찾은 김에 제 입맛대로 정리해 보았습니다.


test_RadioButton.zip





MainWindow.xaml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<Window x:Class="test_RadioButton.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:test_RadioButton"
        mc:Ignorable="d"
        Title="MainWindow" Height="365" Width="641">
    <Grid>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
            <StackPanel x:Name="btn3">
                <GroupBox Header="GroupBox" VerticalAlignment="Top" Height="100">
                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                    <StackPanel x:Name="radioButtonPanel" VerticalAlignment="Top">
                        <RadioButton Content="미팅" Tag="1"/>
                        <RadioButton Content="회의" Tag="2"/>
                        <RadioButton Content="식사" Tag="3"/>
                        <RadioButton Content="미팅1" Tag="4"/>
                        <RadioButton Content="회의1" Tag="5"/>
                        <RadioButton Content="식사1" Tag="6"/>
                        <RadioButton Content="미팅2" Tag="7"/>
                        <RadioButton Content="회의2" Tag="8"/>
                        <RadioButton Content="식사2" Tag="9"/>
                    </StackPanel>
                </ScrollViewer>
            </GroupBox>
                <Button x:Name="btn1" Content="Button" HorizontalAlignment="Center" VerticalAlignment="Top" Width="80" Height="30" Click="Button_Click"/>
                
                <GroupBox Header="GroupBox" VerticalAlignment="Top" Height="100">
                    <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                        <StackPanel x:Name="radioButtonPanel2" VerticalAlignment="Top">
                            <RadioButton Content="미팅" Tag="1"/>
                            <RadioButton Content="회의" Tag="2"/>
                            <RadioButton Content="식사" Tag="3"/>
                            <RadioButton Content="미팅1" Tag="4"/>
                            <RadioButton Content="회의1" Tag="5"/>
                            <RadioButton Content="식사1" Tag="6"/>
                            <RadioButton Content="미팅2" Tag="7"/>
                            <RadioButton Content="회의2" Tag="8"/>
                            <RadioButton Content="식사2" Tag="9"/>
                        </StackPanel>
                    </ScrollViewer>
                </GroupBox>
                <Button x:Name="btn2" Content="Button" HorizontalAlignment="Center" VerticalAlignment="Top" Width="80" Height="30" Click="Button_Click"/>
 
                <GroupBox Header="GroupBox" VerticalAlignment="Top" Height="100">
                    <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                        <StackPanel x:Name="radioButtonPanel3" VerticalAlignment="Top">
                            <RadioButton Content="미팅" Tag="1"/>
                            <RadioButton Content="회의" Tag="2"/>
                            <RadioButton Content="식사" Tag="3"/>
                            <RadioButton Content="미팅1" Tag="4"/>
                            <RadioButton Content="회의1" Tag="5"/>
                            <RadioButton Content="식사1" Tag="6"/>
                            <RadioButton Content="미팅2" Tag="7"/>
                            <RadioButton Content="회의2" Tag="8"/>
                            <RadioButton Content="식사2" Tag="9"/>
                        </StackPanel>
                    </ScrollViewer>
                </GroupBox>
                <Button Content="Button" HorizontalAlignment="Center" VerticalAlignment="Top" Width="80" Height="30" Click="Button_Click"/>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Window>
 
cs




MainWindow.xaml.cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Linq;
using System.Windows;
using System.Windows.Controls;
 
namespace test_RadioButton
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
 
            if (btn.Name == "btn1")
            {
                // Group1
                RadioButton radioButton = (from element in radioButtonPanel.Children.Cast<UIElement>()
                                           where element is RadioButton && (element as RadioButton).IsChecked.Value
                                           select element).SingleOrDefault() as RadioButton;
 
                string content = radioButton.Content as string// 미팅, 회의, 식사 
                bool check = radioButton.IsChecked.Value; // True, False 
                string tag = radioButton.Tag as string// 1, 2, 3 
                MessageBox.Show(content);
            }
 
            if (btn.Name == "btn2")
            {
                // Group2
                RadioButton radioButton2 = (from element in radioButtonPanel2.Children.Cast<UIElement>()
                                            where element is RadioButton && (element as RadioButton).IsChecked.Value
                                            select element).SingleOrDefault() as RadioButton;
 
                string content2 = radioButton2.Content as string// 미팅, 회의, 식사 
                bool check2 = radioButton2.IsChecked.Value; // True, False 
                string tag2 = radioButton2.Tag as string// 1, 2, 3 
                MessageBox.Show(content2);
            }
 
            if (btn.Name == "btn3")
            {
                // Group3
                RadioButton radioButton3 = (from element in radioButtonPanel3.Children.Cast<UIElement>()
                                            where element is RadioButton && (element as RadioButton).IsChecked.Value
                                            select element).SingleOrDefault() as RadioButton;
 
                string content3 = radioButton3.Content as string// 미팅, 회의, 식사 
                bool check3 = radioButton3.IsChecked.Value; // True, False 
                string tag3 = radioButton3.Tag as string// 1, 2, 3 
                MessageBox.Show(content3);
            }
        }
    }
}
 
cs



참고자료

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040102&docId=279623164

https://blog.naver.com/june_621/220555587123


728x90
반응형