【问题标题】:Disabled MenuItem is not greyed out on Windows 7已禁用的 MenuItem 在 Windows 7 上未显示为灰色
【发布时间】:2016-09-01 05:06:39
【问题描述】:

我的应用中有一个模板菜单,里面有一个用于删除模板的菜单项。当没有现有模板时,菜单项被禁用。我将 IsEndabled 属性绑定到 Templates.Count 并且在 Windows 8 或 10 上一切正常,但在 Windows 7 上,该项目没有变灰(但被禁用)。

“删除模板...”菜单项的我的 xaml:

<MenuItem Header="{DynamicResource RemoveTemps}" 
          IsEnabled="{Binding Templates.Count, 
          Converter={StaticResource intToBoolConverter}}" 
          Command="{Binding RemoveTemplatesCommand, Mode=OneWay}"/>

ViewModel 类的片段:

public class MainWindowViewModel : ObservableObject
{
    private StringCollection _templates = Properties.Settings.Default.Templates;
    public ObservableCollection<string> Templates { get; set; } = new ObservableCollection<string>();

    public MainWindowViewodel()
    {
        foreach (string s in _templates)
        {
            Templates.Add(s);
        }
    }

}

如果为了解决问题而缺少任何信息,请告诉我。

【问题讨论】:

    标签: c# wpf windows-7


    【解决方案1】:

    我遇到了类似的问题。

    请尝试添加参数

    与您的绑定异步:

    https://msdn.microsoft.com/en-us/library/system.windows.data.binding.isasync(v=vs.110).aspx

    这样做

    <MenuItem Header="{DynamicResource RemoveTemps}" 
              IsEnabled="{Binding Templates.Count, 
              Converter={StaticResource intToBoolConverter}}" 
              Command="{Binding RemoveTemplatesCommand, Mode=OneWay, IsAsync=True}"/>
    

    它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2011-06-19
      • 2020-11-26
      • 2011-12-03
      相关资源
      最近更新 更多