에서 Command.CanExecute 사용 방법 설정 (제거 외부 레이아웃 코드)입니다 :이 자식 컨트롤 여기
Window.xaml
<Button Name="btn_Next" Command="NextPage">Next</Button>
<ContentControl Name="contentControl1" >
<Binding ElementName="MainWindow" Path="CurrentPage"/>
</ContentControl>
Window.xaml.cs 생성자
var nextCommand = new CommandBinding(NavigationCommands.NextPage);
nextCommand.CanExecute += nextCommand_CanExecute;
nextCommand.Executed += nextCommand_Executed;
CommandBindings.Add(nextCommand);
이것은 기본 예제에서 유용합니다. nextCommand_CanExecute
은 CurrentPage가 마지막 페이지인지 확인합니다. 그러나, 그 논리는 현재 배열을 검사하고 선형 탐색에만 작동합니다. 그러나 내비게이션은 나무처럼 보이므로 작동하지 않을 것입니다. contentControl1
의 항목이 다른 방향으로 분기하는 경우가 있습니다. 그래서 CurrentPage
사용자 컨트롤에 CanExecute
을 무시할 수있는 권한을 부여하고 싶습니다. 제 문제는 UserControl
을 CanExecute
으로 시작하는 방법을 알아낼 수 없다는 것입니다. CommandTarget
설정을 사용하지 않으려 고 시도했습니다. 내 자식 컨트롤에는 결코 CanExecute
메소드가 트리거되지 않았습니다. 심지어 부모 창 CanExecute e.ContinueRouting = true
사용하려고했습니다. 도움이 될 경우 사용자 컨트롤 코드는 다음과 같습니다.
사용자 제어 Constrtuctor :
var nextCommand = new CommandBinding(NavigationCommands.NextPage);
nextCommand.CanExecute += nextCommand_CanExecute;
CommandBindings.Add(nextCommand);
사용자 제어 CanExecute 방법 : 아래로 다시 거품 다음을 시작하고 컨트롤에 시각적 트리의 루트에서
private void nextCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = false;
e.Handled = true;
}
젠장, 내가해야 할 일이 있을지도 모르는 ... 이미 내장 된 것이 있었으면 좋겠다. –
내장 된 것을 작동시킬 수있는 유일한 방법은 내비게이션을 집어 넣는 것이라고 생각한다. 버튼은 사용자 컨트롤의 내부에 있으며, 사용자 컨트롤처럼 보이지 않습니다. –