简体   繁体   English

menuitem 不适用于 ischecked 属性

[英]menuitem wont work for ischecked property

i have a menuitem to which i have included ischecked property.我有一个菜单项,其中包含 ischecked 属性。 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. menuitem 的值始终保持为真。

.xaml .xaml

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

.cs 。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"假设 DataContext 是正确的,您只缺少 IsCheckable="True"

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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