RelayCommand not firing on MenuItem click WPF MVVM

安稳与你 提交于 2019-12-04 15:02:14

Change your XAML to

<Menu Height="21" Margin="0,-2,0,0" VerticalAlignment="Top" Grid.ColumnSpan="2">
    <MenuItem Header="File">
        <MenuItem Header="Import" Command="{Binding ImportFileCommand}" />
    </MenuItem>
</Menu>

In your example, the "Import" content of the MenuItem element implicitly creates a child MenuItem of the parent File MenuItem. This child MenuItem has no Command property defined and so is unable to be executed. Apparently the executability of the Command defined on the parent MenuItem is overridden by the sub-menu expansion functionality.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!