是否有方法将Label绑定到命令,以便在发生特定事件(而非触摸事件(时,该命令将触发
有人做过这样的事吗?
当您使用MVVM时,我们可以在代码后面激发事件。。
参见以下示例:
在Xaml代码隐藏中,重写OnBindingContextChanged((方法并在其中注册property changed事件。因此,每当bindable属性中的值发生变化时,就会触发此事件。您可以检查此事件中的属性名称并执行逻辑操作。
查看模型声明
private MyApplicationsViewModel bindingv;
BindingContext覆盖,
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
bindingv = (this.BindingContext as MyApplicationsViewModel);
if (bindingv != null)
{
bindingv.PropertyChanged += Bindingv_PropertyChanged;
}
}
PropertyChanged事件方法应该在下面,你可以通过检查你之前分配的属性来添加你的逻辑,
async void Bindingv_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(bindingv.FirstName)) // your property name which is used in the label binding
{
}
}