명령 단추에 대해 사용자 지정 CanExecuteChanged 이벤트를 수행하려고합니다. 내부 CanExecuteChanged 이벤트 canExecute 값을 변경할 때 몇 가지 할 싶습니다하지만 Button 및 ICommandSource 구현에서 파생 된 사용자 지정 명령 단추 클래스를 구현하여 수행 할 싶지 않아요. 또한 CanExecute 메서드에 내 물건을 사용하고 싶지 않습니다.WPF에서 명령을 사용하여 사용자 지정 CanExecuteChanged 이벤트 구현
아이디어가 있으십니까?
감사합니다.
<Page xmlns:local="clr-namespace:MySolution" ....>
<Page.CommandBindings>
<CommandBinding Command="{x:Static local:MyNameSpace.MyClass.MyRCmd}"
Executed="MyCmdBinding_Executed"
CanExecute="MyCmdBinding_CanExecute"/>
</Page.CommandBindings>
...
<Button Command="{x:Static local:MyNameSpace.MyClass.MyRCmd}" ... />
...
</Page>
을 그리고 숨김 페이지 코드 :
namespace MyNameSpace
{
public partial class MyClass : Page
{
...
public static RoutedCommand MyRCmd = new RoutedCommand();
public event EventHandler CanExecuteChanged;
private void CanExecuteChanged(object sender, EventArgs e)
{
// Here is my problem: How to say to execute this when CanExecute value is
// changing? I would like to execute this on CanExecute value changed.
// I think somewhere I can tell compiler the handler for CanExecutedChanged is
// this. How to?
}
private void MyCmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
// Do my stuff when CanExecute is true
}
private void MyCmdBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (....)
{
e.CanExecute = true;
}
else
{
e.CanExecute = false;
}
}
...
} // end class
} // end namespace
내 문제 XAML에서
:
좋아요, 그렇지만 처리하고 구현하는 방법에 동의합니까? 나는 예를 들어, 실행되고 CanExecute 방법과 동일한 기능을 수행 할 싶습니다 개인 무효 CanExecuteChanged (개체 보낸 사람, EventArgs입니다 전자) 내 문제는 내가 방법을 모르는 것입니다 { // 내 물건 를 수행} 이 이벤트를 명령 단추에 바인딩합니다. 내 XAML에서 내가 할 : CommandBinding을> < "MyCommand" 실행 된 = CanExecute = "MyCanExecute" "MyExecuted"= 명령을 CommandBinding을>을
"MyCommand"란 무엇입니까? 어떻게 정의됩니까? 그리고 코드를 게시하기 위해 답을 편집하십시오 : 코멘트에서 읽을 수 없습니다 –
죄송합니다, 내가하고 싶은 것에 대한 예제를 게시했습니다. 나는 그것을 더 읽기 쉽도록 대답으로 올렸다. – user304602