【问题标题】:Xamarin.Forms MVVM - Is there a way to Unset a Binding?Xamarin.Forms MVVM - 有没有办法取消绑定?
【发布时间】:2016-11-03 03:37:08
【问题描述】:

有没有办法以编程方式取消绑定?比如:

myLabel.UnsetBinding(Label.TextColorProperty);

肯定有办法做到这一点?

【问题讨论】:

    标签: mvvm data-binding xamarin xamarin.forms


    【解决方案1】:

    您正在寻找RemoveBinding() 方法:https://developer.xamarin.com/api/member/Xamarin.Forms.BindableObject.RemoveBinding/p/Xamarin.Forms.BindableProperty/

    你的例子:

    myLabel.RemoveBinding(Label.TextColorProperty);
    

    【讨论】:

    • 这到底是怎么回事 - 为什么谷歌搜索“xamarin 表单删除绑定”不会提出这个问题?奇怪。
    【解决方案2】:

    绑定附加到 BindableProperty,而不是类。

    您可以将属性设置为其他任何值,绑定将消失;

    myLabel.Text = String.Empty;
    

    注意:以上(Keith's)是正确答案。

    【讨论】:

    • 哦,太棒了 - 我会试试看。
    猜你喜欢
    • 2019-12-13
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 2012-07-11
    相关资源
    最近更新 更多