zoukankan      html  css  js  c++  java
  • WPF递归设置CheckBox与TextBox禁用联动

      

     <Grid Grid.Column="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="80"/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="10"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <CheckBox Content="用水量" 
                                          Tag="WaterConsumption"
                                          Checked="CheckBox_Checked" 
                                          Unchecked="CheckBox_Unchecked"
                                          Style="{StaticResource CheckBox_Style}"/>
                                <dmcontrols:DMTextBox  Grid.Column="1"
                                              VerticalContentAlignment="Center"
                                              PreviewTextInput="DMTextBox_PreviewTextInput"
                                              KeyDown="Combo_KeyDown"
                                              input:InputMethod.IsInputMethodEnabled="False"
                                              Margin=" 10,5,10,5"
                                              Height="28"
                                              Tag="WaterConsumption"
                                              MaxLength="10"
                                              FontSize="18"
                                              />
                                <TextBlock  Text="-" Style="{StaticResource TextBlock_Style}"/>
                                <dmcontrols:DMTextBox  Grid.Column="3"
                                              VerticalContentAlignment="Center"
                                              PreviewTextInput="DMTextBox_PreviewTextInput"
                                              KeyDown="Combo_KeyDown"
                                              input:InputMethod.IsInputMethodEnabled="False"
                                              Margin=" 10,5,10,5"
                                              Height="28"
                                              Tag="WaterConsumption"
                                              MaxLength="10"
                                              FontSize="18"                                          
                                              />
                            </Grid>
            /// <summary>
            /// 递归初始化禁用Textbox
            /// </summary>
            private void SettingTextBoxIsenable(Grid grid, List<string> strList)
            {
                foreach (UIElement uiElement in grid.Children)
                {
                    if (uiElement is Grid)
                    {
                        SettingTextBoxIsenable((uiElement as Grid), strList);
                    }
                    else if (uiElement is DMTextBox)
                    {
    
                        if (strList.Contains((uiElement as DMTextBox).Tag.ToString()))
                        {
                            (uiElement as DMTextBox).IsEnabled = false;
                            if (!(uiElement as TextBox).IsEnabled)
                            {
                                (uiElement as DMTextBox).Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#A9A9A9"));
                            }
                            else
                            {
                                (uiElement as DMTextBox).Background = new SolidColorBrush(Colors.White);
                            }
                        }
                    }
                }
            }
    
            private void CheckBox_Checked(object sender, RoutedEventArgs e)
            {           
                EnablePriceCompositionControls((sender as CheckBox).Tag.ToString(), (bool)(sender as CheckBox).IsChecked, grid_Reading);
            }
    
            private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
            {
                EnablePriceCompositionControls((sender as CheckBox).Tag.ToString(), (bool)(sender as CheckBox).IsChecked, grid_Reading);
            }
    
            /// <summary>
            /// 递归修改属性
            /// </summary>
            /// <param name="feeCode"></param>
            /// <param name="ischecked"></param>
            /// <param name="grid"></param>
            private void EnablePriceCompositionControls(string feeCode, bool ischecked, Grid grid)
            {
                foreach (UIElement uiElement in grid.Children)
                {
                    if (uiElement is Grid)
                    {
                        EnablePriceCompositionControls(feeCode, ischecked, (uiElement as Grid));
                    }
                    else if (uiElement is DMTextBox)
                    {
    
                        if (feeCode.Equals((uiElement as DMTextBox).Tag.ToString()))
                        {
                            (uiElement as DMTextBox).IsEnabled = ischecked;
                            if (!(uiElement as TextBox).IsEnabled)
                            {
                                (uiElement as DMTextBox).Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#A9A9A9"));
                            }
                            else
                            {
                                (uiElement as DMTextBox).Background = new SolidColorBrush(Colors.White);
                            }
                        }
                    }
                }
            }
  • 相关阅读:
    anaconda版本与python版本对应关系查询网址
    非官方windows二进制Python拓展包
    vscode每次打开文件,出现git弹窗,login i revparse showtoplevel,打印revparse:no such file or directory
    Python 官方文档
    转:Oracle EBS借贷关系
    中文分词的简要实现
    Thinkpad为什么是Thinkpad
    中文分词的应用——网站热点分析
    Blog工具:Zoundry blog writer and GreatNews RSS reader
    SpringBoot校验请求Json参数
  • 原文地址:https://www.cnblogs.com/CityOfThousandFires/p/13445485.html
Copyright © 2011-2022 走看看