简体   繁体   中英

menuitem wont work for ischecked property

i have a menuitem to which i have included ischecked property. when a menu item is clicked it should keep on saving files and when menu item is not clicked it should overwrite the previous saved file. clicking part is working but when it is not clicked it doesnt overwrite. The value of menuitem remains true all the times.

.xaml

 <MenuItem Header="Save" IsChecked="{Binding Saving ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  >
  

.cs

 private bool saving =true;
    public bool Saving
    {
        get
        {
            return saving;
        }
        set
        {
            saving = value;
            RaisePropertyChanged("Saving");
        }
    }

 Configuration.isPrevSave = Saving;

 if (Configuration.isPrevSave == false && Configuration.PreviousFilePath != null && Directory.Exists(Configuration.PreviousFilePath))
                DirectoryInfo.DeleteContents(Configuration.PreviousFilePath);
            else //works
       

Assuming the DataContext is correct you are only missing IsCheckable="True"

<MenuItem Header="Save" IsCheckable="True" IsChecked="{Binding Saving ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM