티스토리 뷰

C#/WPF

WPF tutorial - The RadioButton control

광그로 2017. 6. 22. 15:06

http://www.wpf-tutorial.com/basic-controls/the-radiobutton-control/


라디오 버튼은 단일 선택을 지원합니다.


1
2
3
4
5
6
<StackPanel Margin="10">
        <Label FontWeight="Bold">Are you ready?</Label>
        <RadioButton>Yes</RadioButton>
        <RadioButton>No</RadioButton>
        <RadioButton IsChecked="True">Maybe</RadioButton>
    </StackPanel>
cs


라디오 버튼 그룹


라디오 버튼에 GroupName을 부여하여 개별적으로 선택할 수 있습니다.


1
2
3
4
5
6
7
8
9
10
11
<StackPanel Margin="10">
        <Label FontWeight="Bold">Are you ready?</Label>
        <RadioButton GroupName="ready">Yes</RadioButton>
        <RadioButton GroupName="ready">No</RadioButton>
        <RadioButton GroupName="ready" IsChecked="True">Maybe</RadioButton>
 
        <Label FontWeight="Bold">Male or female?</Label>
        <RadioButton GroupName="sex">Male</RadioButton>
        <RadioButton GroupName="sex">Female</RadioButton>
        <RadioButton GroupName="sex" IsChecked="True">Not sure</RadioButton>
 </StackPanel>
cs



Custom content

라디오 버튼도 체크박스와 마찬가지로 ContentControl 클래스를 상속합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<StackPanel Margin="10">
        <Label FontWeight="Bold">Are you ready?</Label>
        <RadioButton>
            <WrapPanel>
                <Image Source="https://cdn.pixabay.com/photo/2013/07/12/17/00/approved-151676__340.png" Width="16" Height="16" Margin="0,0,5,0" />
                <TextBlock Text="Yes" Foreground="Green" />
            </WrapPanel>
        </RadioButton>
        <RadioButton Margin="0,5">
            <WrapPanel>
                <Image Source="https://cdn.pixabay.com/photo/2017/02/12/21/29/false-2061131__340.png" Width="16" Height="16" Margin="0,0,5,0" />
                <TextBlock Text="No" Foreground="Red" />
            </WrapPanel>
        </RadioButton>
        <RadioButton IsChecked="True">
            <WrapPanel>
                <Image Source="https://cdn.pixabay.com/photo/2013/11/20/09/36/question-mark-213692__340.jpg" Width="16" Height="16" Margin="0,0,5,0" />
                <TextBlock Text="Maybe" Foreground="Gray" />
            </WrapPanel>
        </RadioButton>
    </StackPanel>
cs



WrapPanel을 사용하여 Image와 TextBlock을 함께 묶어 이미지를 선택해도 라디오 버튼이 활성화 됩니다.

'C# > WPF' 카테고리의 다른 글

WPF tutorial - Control ToolTips  (0) 2017.06.22
WPF tutorial - The PasswordBox control  (0) 2017.06.22
WPF tutorial - The CheckBox control  (0) 2017.06.22
WPF tutorial - 복습 및 simple login  (0) 2017.06.21
WPF tutorial - The TextBox control  (0) 2017.06.20
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
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
글 보관함