• 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);
                            }
                        }
                    }
                }
            }
  • 相关阅读:
    (转)史上最简单的SpringCloud教程 | 第五篇: 路由网关(zuul)(Finchley版本)
    (转)史上最简单的SpringCloud教程 | 第四篇:断路器(Hystrix)(Finchley版本)
    (转)史上最简单的SpringCloud教程 | 第三篇: 服务消费者(Feign)(Finchley版本)
    (转)史上最简单的SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)(Finchley版本)
    (转)史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现Eureka(Finchley版本)
    axios使用及配置明细小记
    明明白白ES6——Promise 对象
    状态压缩—骑士
    蒙德里安的梦想Poj2411
    bzoj4033
  • 原文地址:https://www.cnblogs.com/CityOfThousandFires/p/13445485.html
Copyright © 2020-2023  润新知