目前绑定到“可见性”设置Hidden = true。如何创建一个通用的Visibility绑定,它也会更改约束:将视图高度设置为0?
答案 0 :(得分:1)
有关创建绑定的教程,请参阅http://mvvmcross.blogspot.com/
上的N = 28视频要替换现有的可见性绑定,只需根据https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Binding.Touch/Target/MvxUIViewVisibleTargetBinding.cs
创建自己的类public class MyUIViewVisibleTargetBinding : MvxBaseUIViewVisibleTargetBinding
{
public MyUIViewVisibleTargetBinding(UIView target)
: base(target)
{
}
protected override void SetValueImpl(object target, object value)
{
var view = View;
if (view == null)
return;
var visible = value.ConvertToBoolean();
// your code here
// - in place of or in addition to:
// view.Hidden = !visible;
}
}
并将此注册为Setup
使用的最后一步:
protected override void InitializeLastChance()
{
base.InitializeLastChance();
var registry = Mvx.Resolve<IMvxTargetBindingFactoryRegistry>();
registry.RegisterCustomBindingFactory<UIView>("Visible",
view =>
new MyUIViewVisibleTargetBinding(view));
}
有关替换现有绑定的更多信息,请参阅MVVMCross Binding decimal to UITextField removes decimal point
请注意,如果您要替换所有Visible
个绑定,那么您可能希望替换所有Visible
,Visibility
和Hidden
- 请参阅{{3}中的注册}}