Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按下按钮以重复命令_C#_Wpf_Relaycommand - Fatal编程技术网

C# 按下按钮以重复命令

C# 按下按钮以重复命令,c#,wpf,relaycommand,C#,Wpf,Relaycommand,我在我的WPF项目中有一个按钮,我希望它在我按下按钮时反复执行相同的命令。我可以使用RepeatButton,但我更喜欢命令在运行(在它自己的任务中)后立即再次执行,而不是依赖RepeatButton控件的延迟和间隔属性 我不介意使用按钮单击方法,但是命令操作运行时间很长,执行时间将取决于ExecuteParameter的值(在本例中,是表示机器物理位置的双元组) XAML: C#: SystemCommands.AddSubSystemCommand(SystemRef,CommandNa

我在我的WPF项目中有一个按钮,我希望它在我按下按钮时反复执行相同的命令。我可以使用RepeatButton,但我更喜欢命令在运行(在它自己的任务中)后立即再次执行,而不是依赖RepeatButton控件的延迟和间隔属性

我不介意使用按钮单击方法,但是命令操作运行时间很长,执行时间将取决于ExecuteParameter的值(在本例中,是表示机器物理位置的双元组)

XAML:


C#:

SystemCommands.AddSubSystemCommand(SystemRef,CommandNames.IncrAngle,newrelaycommand(
o=>
{
双角度=(双)o>5?5:(双)o;
double-nextX=MotionControl.LiveX;
double nextB=MotionControl.LiveB+AngleIncr;
nextB=nextB>=45?45:nextB;
Task.Run(()=>
{
ExecuteCommand(CommandNames.GotoPosition,新元组(nextX,nextB));
});
},       
_ => 
{
if(MotionControl==null)
返回false;
return!MotionControl.InMotionCheckStatus;
}));
if(MotionControl!=null)
{
MotionControl.MotionChanged+=SystemCommands.GetRelayCommand(CommandNames.IncrAngle).CanExecutePropertyChangedNotification;
}
更新:我可以看到一些人已经探头看了一眼。如果有人对我如何改进问题本身提出建议,我欢迎反馈。由于我名声不好,你可能会猜到我在这方面是新手。

他们应该做你想做的事

->重复开始后,重复之间的时间量(以毫秒为单位)。该值必须为非负

->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>


顺便说一句,第二个lambda可以简化:
\u=>MotionControl!=空&!MotionControl.InMotionCheckStatus
非常好的建议。谢谢abatishchev。当我试着让所有的组件正常工作时,它现在显得冗长而怪异。Terrance,我很高兴自己错了,我知道RepeatButton控件在命令绑定上的效果和在按钮单击方法上的效果一样好。感谢所有为我看这个的人。
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;
}
<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>