码迷,mamicode.com
首页 > 其他好文 > 详细

CheckBox状态多选

时间:2016-04-08 09:01:26      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

前:

 1   <StackPanel Margin="10">
 2             <Label FontWeight="Bold">Application Options</Label>
 3             <StackPanel Margin="10,5">
 4                 <CheckBox IsThreeState="True" Name="cbAllFeatures" Checked="cbAllFeatures_CheckedChanged" Unchecked="cbAllFeatures_CheckedChanged">Enable all</CheckBox>
 5                 <StackPanel Margin="20,5">
 6                     <CheckBox Name="cbFeatureAbc" Checked="cbFeature_CheckedChanged" Unchecked="cbFeature_CheckedChanged">Enable feature ABC</CheckBox>
 7                     <CheckBox Name="cbFeatureXyz" IsChecked="True" Checked="cbFeature_CheckedChanged" Unchecked="cbFeature_CheckedChanged">Enable feature XYZ</CheckBox>
 8                     <CheckBox Name="cbFeatureWww" Checked="cbFeature_CheckedChanged" Unchecked="cbFeature_CheckedChanged">Enable feature WWW</CheckBox>
 9                 </StackPanel>
10             </StackPanel>
11         </StackPanel>
 1         private void cbAllFeatures_CheckedChanged(object sender, RoutedEventArgs e)
 2         {
 3             bool newVal = (cbAllFeatures.IsChecked == true);
 4             cbFeatureAbc.IsChecked = newVal;
 5             cbFeatureXyz.IsChecked = newVal;
 6             cbFeatureWww.IsChecked = newVal;
 7         }
 8 
 9         private void cbFeature_CheckedChanged(object sender, RoutedEventArgs e)
10         {
11             cbAllFeatures.IsChecked = null;
12             if ((cbFeatureAbc.IsChecked == true) && (cbFeatureXyz.IsChecked == true) && (cbFeatureWww.IsChecked == true))
13                 cbAllFeatures.IsChecked = true;
14             if ((cbFeatureAbc.IsChecked == false) && (cbFeatureXyz.IsChecked == false) && (cbFeatureWww.IsChecked == false))
15                 cbAllFeatures.IsChecked = false;
16         }

 

CheckBox状态多选

标签:

原文地址:http://www.cnblogs.com/billly/p/5366428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!