gpt4 book ai didi

android - MvvmCross Xamarin.Android FloatingActionButton 切换可见性

转载 作者:行者123 更新时间:2023-11-29 16:58:09 30 4
gpt4 key购买 nike

这是我的 FloatingActionButton:

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_retailer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:tint="@android:color/white"
app:backgroundTint="@color/colorPrimary"
app:srcCompat="@drawable/ic_add_black_24dp"
local:MvxBind="Visibility IsAddButtonVisible, Converter=Visibility" />

它的可见性属性通过 MvvmCross 绑定(bind)到 IsAddButtonVisible:

private bool _isAddButtonVisible = true;
public bool IsAddButtonVisible
{
get
{
return _isAddButtonVisible;
}
set
{
_isAddButtonVisible = value;
RaisePropertyChanged(() => IsAddButtonVisible);
}
}

当我改变 bool 值时

ViewModel.IsAddButtonVisible = false;

...没有任何反应。我在这里做错了什么?提前致谢!

编辑:当我使用 Visible 进行绑定(bind)时,切换有效

local:MvxBind="Visible IsAddButtonVisible"

但现在我在 FloatingActionButton 上看不到任何隐藏/显示动画...

最佳答案

您必须使用自定义绑定(bind)来使用方法调用而不是 Visibility ViewStates 更改。


创建目标绑定(bind),根据您绑定(bind)到的 bool 值处理执行显示和隐藏方法调用。

public class FloatingActionButtonAnimateVisibleTargetBinding
: MvxAndroidTargetBinding
{
protected FloatingActionButton View => (FloatingActionButton)Target;

public FloatingActionButtonAnimateVisibleTargetBinding(FloatingActionButton target)
: base(target)
{
}

public override Type TargetType => typeof(bool);

protected override void SetValueImpl(object target, object value)
{
var isVisible = value.ConvertToBoolean();
var floatingActionButton = target as FloatingActionButton;

if (isVisible)
floatingActionButton.Show();
else
floatingActionButton.Hide();
}

在您的平台 Setup.cs 中注册自定义绑定(bind)

protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
base.FillTargetFactories(registry);

registry.RegisterCustomBindingFactory<FloatingActionButton>(
"VisibleAnim",
button => new FloatingActionButtonAnimateVisibleTargetBinding(button));
}

那么您应该能够在 XML 中使用绑定(bind)

local:MvxBind="VisibleAnim IsAddButtonVisible"

关于android - MvvmCross Xamarin.Android FloatingActionButton 切换可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43938800/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com