user1021167
user1021167

Reputation:

how to check is the checkbox checked in WPF Prism

I have a UserControlButtons.Xaml in this there is checkbox and button Save. when the save is clicked and if checkbox is checked then open a popup.Save is always enabled.

          <CheckBox x:Name="checkBox1" VerticalAlignment="Center"  Content="Add To Time Sheet" FontSize="14" Grid.Row="0" Grid.Column="2" Margin="2,2,2,2"
             IsChecked="{Binding ElementName=UserControlButtons, Path=UserControlButtonsBL .IsCheckedComplete,Mode=TwoWay}"

In the UserControlButtonsViewModel DelegateCommand Save has CanSave and Save

In the BL Module there is UserControlButtonsBL here i declared the property for checkbox

     private bool _isCheckedComplete;
     public bool IsCheckedComplete
     {
         get { return _isCheckedComplete; }
         set
         {
             _isCheckedComplete = value;

         }
     }

in the code behind i added the dependency property

    public UserControlButtonsBL UserControlButtonsBL 
    {
        get
        {
            return (UserControlButtonsBL )GetValue(UserControlButtonsBLProperty);
        }
        set
        {
            SetValue(UserControlButtonsBLProperty, value);
        }
    } 

here even when i checked the checkbox IsCheckedComplete giving me false

Upvotes: 1

Views: 2015

Answers (1)

Ankesh
Ankesh

Reputation: 4885

Here in the checkbox you should make the binding Mode two way and also set the update source trigger to PropertyChanged

           <CheckBox x:Name="checkBox1" VerticalAlignment="Center"  Content="Add To Time Sheet" FontSize="14" Grid.Row="0" Grid.Column="2" Margin="2,2,2,2"
         IsChecked="{Binding ElementName=UserControlButtons, Path=UserControlButtonsBL .IsCheckedComplete,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  

here i am assuming that you have set your DataContext Correctly.... if you check box is in UserControl which has a DataContext as myDataCntext then binding path will be Directly the property ie IsChecked

Upvotes: 2

Related Questions