WPF:MenuItem.CommandParameter绑定设置为null

 zhoukaipc 发布于 2023-02-09 12:44

我为数据网格定义了以下ContextMenu:


    
        
            
        
    

CommandViewModel类的定义如下:

public class CommandViewModel : ICommandViewModel
    {
        public CommandViewModel(string name, Image icon, ICommand command, object commandParameter = null, int index = 0)
        {
            Name = name;
            Icon = icon;
            Command = command;
            CommandParameter = commandParameter;
            Index = index;
        }

        public string Name { get; set; }
        public Image Icon { get; set; }
        public ICommand Command { get; set; }
        public object CommandParameter { get; set; }
        public int Index { get; set; }     
    }

当我右键单击网格中的一行时,ContextMenu的每个MenuItem的样式都正确。MenuItem的图标,标签和命令符合预期。但是,应将命令参数CommandViewModel.CommandParameter作为参数传递给绑定到MenuItem.Command的RelayCommand。该参数为null。

我相当确定该绑定可用的命令参数不为null。这是在.NET 4.0上运行的WPF应用程序。

任何人都经历过吗?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有