1
<Button.ContextMenu>
<ContextMenu x:Name="Conn_Context_button" Style="{StaticResource LeftContextMenuStyle}">
<MenuItem Style="{StaticResource LeftContextMenuItemStyle}" Header="{x:Static properties:ResourceWrapper.Dashboard_Connection_Delete}" Click="MenuItem_DeleteConnection_Click" />
<MenuItem Style="{StaticResource LeftContextMenuItemStyle}" Header="{x:Static properties:ResourceWrapper.Dashboard_Connection_Refresh}" Command="{Binding MyViewModel.RefreshCommand}" />
</ContextMenu>
MyViewModel.cs
public RelayCommand RefreshCommand { get; set; }
RefreshCommand = new RelayCommand(RefreshConnection);
private void RefreshConnection(object sender)
{
//My Logic
}
這裏RefreshCommand不點火當我點擊刷新菜單項
也許使用ICommand? – Whencesoever
也許datacontext不正確,請檢查輸出中的綁定錯誤。如果'MyViewModel'是datacontext,'Command =「{Binding RefreshCommand}'將會解決這個問題。 – Natxo
這不是那麼容易:試試這個http://stackoverflow.com/questions/9994241/mvvm-binding-command-to- contextmenu-item –