在同一Xamarin视图上同时使用"Clicked"和"Command"时如何工作? [英] How do `Clicked` and `Command` work when they are both used on the same Xamarin view?

查看:140
本文介绍了在同一Xamarin视图上同时使用"Clicked"和"Command"时如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XAML中的同一视图上附加了Command(在我的viewModel中)和一个Clicked事件(在我后面的代码中),我注意到一些奇怪的结果.我这样做是因为我希望视图在执行命令的代码后立即得到关注:

I have a Command (in my viewModel) and a Clicked event (in my code behind) attached to the same view in my XAML, and I am noticing some weird results. I am doing this because I would like a view to receive focus right after the code for the command in executed:

  1. CommandClicked事件是否同步异步执行?
  2. 使用此方法是否有任何不利影响.
  3. 有没有更好的方法可以解决这个问题?
  1. Do the Command and the Clicked event execute synchronously or asynchronously?
  2. Are there any adverse effects to using this approach.
  3. Is there a better way I could handle this?

推荐答案

是的,Click事件是异步执行的.但是,我相信命令不是.它们在相关联的动作执行后立即执行.

Yes, the Click events are executed asynchronously. However, I believe the commands are not. They are executed right after the associated action being performed.

我的建议是不要将两者都用于您要的内容.因为只要线程和处理器空闲,就会处理事件.因此,您不能依靠它来满足您的要求,因为它取决于其他一些操作.

My suggestion would be not to use these both together for what you are looking for. Because events will be handled whenever the thread and processor is free. So you cannot rely on it for your requirement as it depends on some other action.

您可以通过使用Xamarin表单中的行为"来实现所需的目标.请参阅下面的链接以获取更多详细信息.

You might achieve what you want by using the Behaviors in Xamarin forms. Refer below links for more details.

https://docs.microsoft .com/en-us/xamarin/xamarin-forms/app-fundamentals/behaviors/creating

这篇关于在同一Xamarin视图上同时使用"Clicked"和"Command"时如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆