2014-11-07 5 views
1

이 코드가 있습니다프로그래밍 방식으로 AppBarButton을 탭하는 방법은 무엇입니까?

async private void InformUserOfRenameOption(string platypusName) 
{ 
    CoreWindowDialog cwd = new CoreWindowDialog(String.Format(
     "This platypus has been given the default name {0}. Do you want to change it?", platypusName)); 
    cwd.Commands.Add(new UICommand { Label = "Yes", Id = 0 }); 
    cwd.Commands.Add(new UICommand { Label = "No", Id = 1 }); 
    cwd.Commands.Add(new UICommand { Label = "Cancel", Id = 2 }); 
    cwd.CancelCommandIndex = 2; 
    IUICommand cmd = await cwd.ShowAsync(); 
    //if (cmd.Id == 0) <= 'Operator '==' cannot be applied to operands of type 'object' and 'int' 
    if (Convert.ToInt32(cmd.Id) == 0) 
    { 
     appbarbtnRenamePlatypus.Tapped(); 
    } 
} 

을 ...하지만 프로그래밍 방식 AppBarButton를 누릅니다 내 시도는 컴파일 타임 오류와 함께 실패합니다 "이벤트 'Windows.UI.Xaml.UIElement.Tapped'할 수있는 유일한 의 왼쪽에 표시되는 + = 또는 - = "

가 어떻게 내가 프로그래밍 방식으로 버튼이나,보다 구체적으로는 Button.Flyout 플라이 아웃이 날아 얻을를 활용할 수?

+1

[Automation Peers] (http://msdn.microsoft.com/en-us/library/windows/apps/jj219211.aspx)를 사용할 수 있다고 생각합니다. 또는'AppBarButton'에서 확장 한 커스텀 컨트롤을 만들 수 있습니다. –

답변

2

일반적으로 AppBar 버튼의 클릭 핸들러의 코드를 자체 메소드로 리팩터링하면 아무 데나 호출 할 수 있습니다.

더 모험을 느끼는 경우 ICommand을 사용하는 것도 고려해 볼 수 있습니다. 이렇게하면 UI 요소 수 (예 : ButtonBase.Command)를 갖거나 코드에서 직접 호출 할 수 있습니다.