추가 메뉴 항목을 상황에 맞는 메뉴에 추가하고 싶습니다. 이상적으로 항목 validateMenuItem을 사용 가능하게됩니다 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.html 당validateMenuItem 받기 : Xamarin에서 생성 한 액션을 사용하여 NSMenuItem을 실행합니다.
[Action("validateMenuItem:")]
public bool ValidateMenuItem(NSMenuItem item)
{
_logger.DebugFormat("Validating {0} menu item with Action {1}", item.Title, item.Action.Name);
var target = item.Target;
var menuItem = ViewModel.ContextMenu.Where(x => x.Title == item.Title).FirstOrDefault();
if (menuItem != null) {
return menuItem.Command.CanExecute();
}
return false;
}
합니다. 내가 수동으로이 호출되는 작업을 만들 수 있지만 경우에 나는 이벤트 핸들러과 같이 할당하는 경우 :
var nsMenuItem = new NSMenuItem(menuItem.Title,
(sender, e) =>
{
menuItem.Command.ExecuteAsync();
});
nsMenuItem.Target = this;
validateMenuItem : 호출되지 않습니다. 이 메서드를 사용하여 할당 된 작업은 __monomac_internal_ActionDispatcher_activated입니다. https://github.com/xamarin/xamarin-macios/blob/master/src/AppKit/ActionDispatcher.cs (Rolf Bjarne Kvinge을 (도와주세요)). 이후 내 수업 (내 생각에)이 작업이 없어, validateMenuItem 결코 호출되지 않으며 내 메뉴 항목은 절대로 활성화되지 않습니다. 이 작품을 어떻게 만들 수 있습니까?
업데이트. 내보기 컨트롤러에이를 추가하는 경우,
[Action("__monomac_internal_ActionDispatcher_activated:")]
public void MonomacInternalAction(NSObject sender)
{
}
validateMenuItem는 : 새로운 항목에 대해 호출됩니다. 그러나 이벤트 핸들러는이 함수로 대체됩니다. (이 문제는 해결 가능하지 않을 수도 있습니다!)이 액션의 문제 대 내보내기 수 있습니다 - 나는
const string skey = "__monomac_internal_ActionDispatcher_activated:";
[Preserve, Export (skey)]
public void OnActivated (NSObject sender)
{
EventHandler handler = Activated;
if (handler != null)
handler (sender, EventArgs.Empty);
}
이 업데이트 2. 그냥 찾아 볼 https://bugzilla.xamarin.com/show_bug.cgi?id=51343
내가하여 validateMenuItem을 속일 수 있습니다 3. 업데이트
public override bool RespondsToSelector(ObjCRuntime.Selector sel)
{
if (sel.Name.Contains("__monomac_internal_ActionDispatcher_activated")) {
return true;
}
return base.RespondsToSelector(sel);
}
지금 원래 이벤트를 호출하는 방법을 찾을 수 있다면!