顯示具有 RadioButton 標籤的文章。 顯示所有文章
顯示具有 RadioButton 標籤的文章。 顯示所有文章

2015年4月25日 星期六

WPF學習筆記 - 7 WPF 控制項 - CheckBox、RadioButton

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相同

[泰國] 芭達雅大城八日遊 Day7、8 - 瑪哈泰寺、Wat Ratchaburana、帕蒙空博碧寺、帕席桑碧寺、Hua Ro market、Chantharakasem National Museum、Amporn Department Store

第七天行程,早上吃飯店早餐,算不錯吃,只是有螞蟻,但吃完沒拉,所以應該還好 吃飽後飽嘟嘟車,一小時 200 泰銖,比自己叫還便宜,終於要來世界遺產之旅了 第一站:瑪哈泰寺,應該是大城最有名的景點了,入門票大人 120 ,小孩免費,其實不便宜 大城指標性景點...