[재무재표] 위메이드 사업보고서(2020.12)

읽으면 진짜 재무제표 보이는 책   위메이드 사업보고서(2020.12) [재무상태표] 2020년 12월 31일 현재 (단위: 십억원) 자산 220 부채 22 자본 198

[WPF] How to programmatically click a button

Windows Forms 에서는 Button.PerformClick() 함수가 존재하였었는데, 
WPF(Windows Presentation Foundation) 에서는 해당 함수가 존재하지 않는다.

WPF에서 사용할 수 있는 두가지 방법을 소개한다.

<방법1. AutomationPeer 이용>

Sample code :
----------------------------------------------------------------------------
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;

... 
void ButtonClick() {
  ButtonAutomationPeer peer = new ButtonAutomationPeer(TestButton);
  IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
  invokeProv.Invoke();


  NextFunction();

----------------------------------------------------------------------------

 - Invoke() 함수이벤트가 발생하여다음처리(NextFunction)가 진행 후 클릭이벤트가 발생한다.
 - 해당버튼이 Disabled 일 때에는 System.Windows.Automation.ElementNotEnabledException 이 발생한다.


<방법2. RaiseEvent 이용>

Sample code :
----------------------------------------------------------------------------
using System.Windows.Controls.Primitives;
... 
void ButtonClick() {
  TestButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));

  NextFunction();
}
----------------------------------------------------------------------------


 - 클릭이벤트 처리후, 다음처리(NextFunction)가 진행된다.
 - 해당버튼이 Disabled 일 때릭이벤트가 발생한다.

댓글

이 블로그의 인기 게시물

[C#][System.IO.Directory.GetFiles] 지정된 폴더의 파일목록 가져오기

[C#] File to Byte Array, Byte Array to File

[WPF][WebBrowser] Allow Blocked Content Setting