CheckBox - 繼承自ContentControl,可客制化
<StackPanel Margin="10">
<Label
FontWeight="Bold">Application Options</Label>
<CheckBox>Enable feature
ABC</CheckBox>
<CheckBox
IsChecked="True">Enable feature XYZ</CheckBox>
<CheckBox>Enable feature
WWW</CheckBox>
</StackPanel>
// IsChecked="True" - 表示被選取
較複雜的CheckBox,可在CheckBox裡放進TextBlock和Image
<CheckBox IsChecked="True">
<WrapPanel>
<TextBlock>
Enable
feature <Run FontWeight="Bold">XYZ</Run>
</TextBlock>
<Image
Source="/WpfTutorialSamples;component/Images/question.png"
Width="16" Height="16" Margin="5,0" />
</WrapPanel>
</CheckBox>
一個CheckBox通常以ture或false代表它是否被選取,不過可以加上IsThreeState="True",來表視第三種狀態,Ture, False, Null
可以用在一組CheckBox,來表示全選,全不選,只有幾個被選…
最後可以配合Checked, Unchecked,來改變被選取的狀態
RadioButton - 繼承自ContentControl,可客制化
<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>
設計出兩組Radio,以GroupName分組,如不需要分組,可以去掉GroupName,就是六個RadioButton為同一組
客制化RadioButton
<RadioButton Margin="0,5">
<WrapPanel>
<Image
Source="/WpfTutorialSamples;component/Images/cancel.png"
Width="16" Height="16" Margin="0,0,5,0" />
<TextBlock
Text="No" Foreground="Red" />
</WrapPanel>
</RadioButton>
作法與CheckBox相同