버튼 중 하나에 대해 사용자 정의 IComand 클래스를 구현했습니다. 단추는 'MyPage.xaml'페이지에 있지만 사용자 정의 ICommand 클래스는 MyPage 코드 뒤에서가 아니라 다른 클래스에 배치됩니다. 그런 다음 XAML에서 나는 그것의 사용자 지정 명령 클래스와 버튼을 바인딩 할 다음 내가 할 :WPF 버튼을 통한 명령
MyPage.xaml :
<Page ...>
<Page.CommandBindings>
<CommandBinding Command="RemoveAllCommand"
CanExecute="CanExecute"
Executed="Execute" />
</Page.CommandBindings>
<Page.InputBindings>
<MouseBinding Command="RemoveAllCommand" MouseAction="LeftClick" />
</Page.InputBindings>
<...>
<Button x:Name="MyButton" Command="RemoveAllCommand" .../>
<...>
</Page>
및 사용자 정의 명령 단추 클래스 :
// Here I derive from MyPage class because I want to access some objects from
// Execute method
public class RemoveAllCommand : MyPage, ICommand
{
public void Execute(Object parameter)
{
<...>
}
public bool CanExecute(Object parameter)
{
<...>
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
내 문제 버튼에 대한 Execute 및 CanExecute 메소드가 다른 클래스에 있고 Button 뒤에있는 코드가 아닌 MyPage.xaml을 말하는 법이 있습니다. How to say 이러한 메서드는 XAML 페이지에서 RemoveAllCommand 클래스에 있습니다.
또한 마우스 이벤트가 단추에서 생성되어 입력 바인딩을 수행 할 때이 명령을 실행하고 싶습니다. 맞습니까?
감사
안녕하세요, 성공했지만 프로젝트를 만들 때 오류가 발생했습니다. RemoveAllCommand 유형의 인스턴스를 만들 수 없습니다. 내 답변에 설명해 놓았습니다. – toni