我的
WPF项目中有一个按钮,我希望它在按住按钮时反复执行相同的命令.我可以使用RepeatButton,但我的偏好是命令在它完成运行后(在它自己的Task中)再次执行,而不是依赖于RepeatButton控件的延迟和间隔属性.
@H_502_6@
我不介意制作按钮单击方法,但命令操作长时间运行,执行时间将取决于ExecuteParameter的值(在这种情况下是表示机器物理位置的双元组).@H_502_6@
XAML:@H_502_6@
@H_502_6@
<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#:@H_502_6@
@H_502_6@
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; }
更新:我可以看到一些人在看了一眼就戳了戳头.如果有人对我如何改进问题提出建议,我会欢迎反馈意见.由于我缺乏声誉,你可能会猜测我是新手.@H_502_6@
解决方法
Repeat Button应该做你想要的
@H_502_6@
Interval – >重复开始后重复之间的时间量(以毫秒为单位).该值必须是非负的.@H_502_6@
Delay – >在重复开始重复之前,RepeatButton在按下时等待的时间量(以毫秒为单位).@H_502_6@
@H_502_6@
<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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。