2017-12-22 17 views
4

저는 WPF 프로젝트에 버튼이 있으며 버튼을 누르고있을 때 동일한 명령을 계속 실행하려고합니다. RepeatButton을 사용할 수는 있지만 RepeatButton 컨트롤의 지연 및 간격 속성에 의존하는 대신 자체 태스크에서 실행이 완료되면 명령을 다시 실행하는 것이 좋습니다.버튼을 누르고 명령을 반복하십시오.

단추를 클릭하는 방법을 신경 쓰지는 않지만 명령 실행 시간이 오래 걸리며 실행 시간은 ExecuteParameter 값에 따라 달라집니다 (이 경우 컴퓨터의 물리적 위치를 나타내는 두 개의 튜플) .

XAML :

<Button FontFamily="Marlett" FontSize="40" Content="5" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="100" Width="100" Height="50"        
     Command="{Binding IncrBAnglePos}" 
     CommandParameter="{Binding ElementName=slider, Path=Value}"> 
</Button> 

C 번호 :

SystemCommands.AddSubSystemCommand(SystemRef, CommandNames.IncrAngle, new RelayCommand(    
     o => 
     { 
      double AngleIncr = (double)o > 5 ? 5 : (double)o; 
      double nextX = MotionControl.LiveX; 
      double nextB = MotionControl.LiveB + AngleIncr; 
      nextB = nextB >= 45 ? 45 : nextB;  
       Task.Run(() => 
       { 
        SystemCommands.ExecuteCommand(CommandNames.GotoPosition, new Tuple<double,double>(nextX, nextB)); 
       }); 
     },  
     _ => 
     { 
      if (MotionControl == null) 
       return false; 
      return !MotionControl.InMotionCheckStatus; 
     })); 
if (MotionControl != null) 
{ 
    MotionControl.MotionChanged += SystemCommands.GetRelayCommand(CommandNames.IncrAngle).CanExecutePropertyChangedNotification; 
} 

업데이트 : 내가 몇 사람이 모습을 촬영 한 자신의 머리를 찌르고있다 볼 수 있습니다. 누군가가 질문 자체를 개선 할 수있는 방법에 대한 의견이 있으면 의견을 환영합니다. 명성이 부족하여 아마도 내가 새로운 일이라고 추측 할 수 있습니다. 반복은 한 번 시작을 반복하는 사이에, 밀리 초 단위의 시간> 양 -

+0

도중에 제 람다가 단순화 될 수있다!'_ => MotionControl = && 널 – abatishchev

+0

우수 제안 MotionControl.InMotionCheckStatus'. 감사합니다 abatishchev. 그것의 장황하고 이상한 지금은 노력하고있는 동안 모든 구성 요소를 제대로 함께 작동 시키십시오. 나는 그것을 선적하기 전에 리팩터링 할 것이다. – AClark

답변

1

Repeat Button

Interval 찾고있는 것을해야한다. 값은 음수가 아니어야합니다.

Delay -> RepeatButton이 반복 재생되기 전에 눌려지는 동안 대기하는 시간 (밀리 초).

<RepeatButton FontFamily="Marlett" 
     Delay="500" 
     Interval="100" 
     FontSize="40" 
     Content="5" 
     HorizontalAlignment="Center" 
     VerticalAlignment="Top" 
     Margin="100" 
     Width="100" 
     Height="50"   
     Command="{Binding IncrBAnglePos}" 
     CommandParameter="{Binding ElementName=slider, Path=Value}"> 
</RepeatButton> 
+0

Terrance, 나는 틀렸다고 생각하고 RepeatButton 컨트롤이 버튼 클릭 메서드와 마찬가지로 명령 바인딩에서도 올바르게 작동한다는 것을 알게되었습니다. 나를 위해 이것을 보았던 모두에게 감사합니다. – AClark