Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 checkboxes. when one is checked, the other one must be checked and disabled. The code I have so far is like so

Xaml
<CheckBox x:Name="chkSABranches" Content="Apply to all branches" IsChecked="{Binding IsSABranches,ElementName=pgPageTemplate}" Grid.Row="0" Grid.Column="2"/>



In xaml.cs:
public static DependencyProperty IsSABranchesProperty = DependencyProperty.Register("IsSABranches", typeof(bool), typeof(pgAccounts), new PropertyMetadata(false));
        public static DependencyProperty IsSAWarehousesProperty = DependencyProperty.Register("IsSAWarehouses", typeof(bool), typeof(pgAccounts), new PropertyMetadata(false));

  public Boolean IsSABranches
        {
            get
            {
                return (bool)GetValue(IsSABranchesProperty);
            }
            set
            {
                SetValue(IsSABranchesProperty, value);
                NotifyPropertyChanged("IsSABranches");
                NotifyPropertyChanged("IsSAWarehouses");
            }
        }

 public Boolean IsSAWarehouses
        {
            get
            {
                return (bool)GetValue(IsSAWarehousesProperty) || (bool)GetValue(IsSABranchesProperty);
            }
            set
            {
                SetValue(IsSAWarehousesProperty, value);
                NotifyPropertyChanged("IsSAWarehouses");
            }
        }

This doesn't seem to work.. Could anyone please provide some guidance. thanks
Posted

1 solution

C#
public Boolean IsSABranches
       {
           get
           {
               return (bool)GetValue(IsSABranchesProperty);
           }
           set
           {
               SetValue(IsSABranchesProperty, value);
if(value)
IsSAWarehouses = value;
               NotifyPropertyChanged("IsSABranches");
               
           }
       }

public Boolean IsSAWarehouses
       {
           get
           {
               return (bool)GetValue(IsSABranchesProperty);
           }
           set
           {
               SetValue(IsSAWarehousesProperty, value);
               NotifyPropertyChanged("IsSAWarehouses");
           }
       }



To make other check box disabled, eighter write down converter or another wrapper property to return negated value of IsSABranches.

Hope this will solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900