xamarin - 如何在 ViewModel 中获取标签视图以在 xamarin 表单中设置可访问性焦点
问题描述
我有Label
观点,我需要Label
在我的ViewModel
. 我正在使用 Dependency Service 将重点放在 Controls for Accessibility 服务上,DS 需要view
作为参数。
这是我的标签
<Label
AutomationProperties.IsInAccessibleTree="{Binding ShowNoResults}"
IsVisible="{Binding ShowNoResults}"
Text="{Binding ResultsHeader}"/>
我试过Command
了,但 Label 不支持命令。下面的代码也不起作用
var view = GetView() as HomeworkView;
我view
总是越来越null
。我怎样才能解决这个问题?
解决方案
我不太确定你想要实现什么,但你不能从你的视图模型中访问视图元素。
如果你想用控件做点什么,你可以使用消息中心来做,这里是一个例子
在您的视图模型中
MessagingCenter.Send(this, "your message here");
然后在您的页面中,您需要从该视图模型订阅此消息并执行所需的操作
MessagingCenter.Instance.Unsubscribe<ViewModelClassNamedel>(this, "your message here");
MessagingCenter.Instance.Subscribe<ViewModelClassName>(this, "your message here", (data) =>
{
this.youControlName.Focus();
});
推荐阅读
- python - 如何解决缓存表分区元数据从内存中的逐出问题,同时使用 Spark 从 S3 重新分区大量数据?
- regex - 如何创建不包含文本但以指定文本开头的正则表达式?
- python - Heroku 模糊堆栈跟踪上的内部服务器错误
- asp.net-core - HttpContext.Connection.RemoteIpAddress 在服务器上返回 127.0.0.1
- scala - 如何有效地计算/估计非晶石矩阵中数十亿对的余弦相似度?
- python-3.x - 如何杀死在测试中实际启动我的应用程序的线程?
- html - 使用 Jest 对 V-If 进行单元测试
- sql - 如果子查询没有与查询连接,则无法使用不存在关键字
- android - 如何从右侧创建一个工作表幻灯片,就好像它是一个底部工作表对话框?
- android - 带有活动和 PagerView2 的 Android 导航