728x90
반응형
라디오버튼 예제 ( Radio Button / Select Button / 설문조사 / XAML / 디자인 )
필요해서 찾았다가 기왕 찾은 김에 제 입맛대로 정리해 보았습니다.
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
반응형
'Programing (프로그래밍) > WPF & C# (C Sharp)' 카테고리의 다른 글
[자작] ZIP 파일 암호 찾기 (0) | 2018.01.03 |
---|---|
[자작] TimeAlram ( 정시알람 / 정각알람 / 정각알림 / 정시알림 / 날씨 / 기상청 / weather ) (4) | 2018.01.02 |
WPF & C# - 시작프로그램 등록 ( Run / 레지스트리 / 윈도우 시작 / 자동실행 / AutoStart ) (1) | 2018.01.02 |
트레이아이콘 ( TrayIcon / notifyIcon ) (0) | 2018.01.02 |
WPF & C# - DispatcherTimer ( ticks / 타이머 / 초 / 반복 / Repeat / TimeSpan ) (0) | 2017.12.29 |
WPF C# - 단일 스레드 예제( Threading/ Thread ) (0) | 2017.12.28 |
WPF & C# - 스레드 Thread - 네임스페이스 ( Threading/ Thread / 쓰레드 / 쓰래드 / 스래드 / 우선순위 / DispatcherPriority / 디스팩처 / 디스팩쳐 ) (0) | 2017.12.28 |
CLASS 간 변수 공유 , static 변수 ( 고정변수 / 클래스변수 ) (0) | 2017.12.27 |