ICommand를 컨트롤의 이벤트에 연결하는 다양한 구현 방법을 살펴보고 있습니다. 예를 들어, TextBox의 GotFocus는 내 View Model에서 GotFocusCommand를 호출해야합니다. 그런 다음 내 자신의 학습용으로 자체 버전을 구현할 생각이 들었지만 잘 작동하지만 XAML에서는 하나의 이벤트 만 하나의 명령에 연결할 수 있습니다.WPF 이벤트에 대한 또 다른 구현 (문제 있음)
<Button
local:EventToCommand.Event="Click"
local:EventToCommand.Command="{Binding TestCommand}"
/>
을하지만 그렇지 않은 :
<Button
local:EventToCommand.Event="Click"
local:EventToCommand.Command="{Binding ClickCommand}"
local:EventToCommand.Event="GotFocus"
local:EventToCommand.Command="{Binding GotFocusCommand}"
/>
(기본적으로 난 그냥 지정된 이벤트를 찾기 위해 반사를 사용하여 다음 명령을 실행하는 AddEventHandler 할)이 잘 작동
을
중복되면 속성 이름 오류가 발생합니다.
<Button>
<Some Xaml Element>
<local:EventToCommand Event="Click" Command="{Binding ClickCommand}" />
<local:EventToCommand Event="GotFocus" Command="{Binding GotFocusCommand}" />
</Some Xaml Element>
</Button>
명령을 여러 이벤트를 "맵":
는 같은 일을 할 수 있을까?
을 네임 스페이스이
어디에서 가져 오기를 수행 할 수 있습니다 현재 구현은 ba입니다. 이벤트 및 커맨드가 모두 AP이기 때문에 첨부 된 속성에 sed. 그 구현을 사용하여 XAML에서 여러 EventToCommand를 지정하는 방법을 잘 모르겠습니다. 상속 옵션) – Oliver
상속 옵션은 괜찮지 만 XAML에서 EventToCommand 컬렉션을 초기화하는 방법은 무엇입니까? – Oliver
일부 코드로 내 대답을 업데이트했습니다. – mekansm