Click here to Skip to main content
14,644,614 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100