WPF元件使用之CheckBox
阿新 • • 發佈:2021-01-19
CheckBox 是一種非常簡單易用的元件,有啟用/禁用兩種狀態,分別由CheckBox 控制元件的 Checked 和 Unchecked 事件來實現。
IsChecked
IsChecked 屬性來預設設定選中狀態
IsThreeState
CheckBox除了常用的兩種狀態,還存在第三種狀態,當IsThreeState設為true,就開啟了這種"不確定"狀態
<StackPanel Margin="10"> <Label FontWeight="Bold" Background="Chocolate">Code Type</Label> <StackPanel Margin="10,5"> <CheckBox IsThreeState="True" Name="cbSelectAll" Checked="cbSelectAll_CheckedChanged" Unchecked="cbSelectAll_CheckedChanged">Select All</CheckBox> <StackPanel Margin="20,5"> <CheckBox Name="checkBoxName1" IsChecked="True">C#</CheckBox> <CheckBox Name="checkBoxName2" >C++</CheckBox> <CheckBox Name="checkBoxName3" >Python</CheckBox> </StackPanel> </StackPanel> </StackPanel>
如下圖所屬除了選中和未選中之外的狀態