Android MVVMCross中ImageButton的可见性
我有下面的Android MVVMCross中ImageButton的可见性,android,xamarin,mvvmcross,Android,Xamarin,Mvvmcross,我有下面的axml,其中有两个图像按钮,但我只想一次显示一个,并实现一些切换功能 更具体地说,当用户单击button1时,它将隐藏button1,并显示button2,反之亦然。我正在使用MVVMCross模式 <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp" android:paddingLeft="20dp" android:paddingRi
axml
,其中有两个图像按钮,但我只想一次显示一个,并实现一些切换功能
更具体地说,当用户单击button1
时,它将隐藏button1
,并显示button2
,反之亦然。我正在使用MVVMCross
模式
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ImageButton
android:id="@+id/myBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_back" />
<ImageButton
android:id="@+id/myBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_white" />
</RelativeLayout>
我会使用(从NuGet添加)
然后添加:一个bool属性和一个用于在ViewModel中切换bool的命令:
private bool\u boolInViewModel;
公共bool BoolInViewModel
{
获取{return\u boolInViewModel;}
设置{u boolInViewModel=value;RaisePropertyChanged(()=>boolInViewModel);}
}
公共imvx命令CommandToSwitchBool
{
得到
{
返回新的MvxCommand(()=>
{
BoolInViewModel=!BoolInViewModel;
}
);
}
}
然后使用visibility converter(可见性转换器)和Inversed visibility convert(反转可见性转换)绑定到bool,并使用按钮上的click事件命令,如下所示:
非常感谢,它工作得非常完美。很高兴了解逆变器可视性
功能!是的,它还可以做很多很酷的事情,比如将可见性绑定到列表上的计数,以显示/隐藏“列表中没有项目”视图。值得称赞的是,在@IainSmith这里制作插件的家伙们我知道这个插件很旧,但是你能包括相关的名称空间别名吗?(如“应用”)此外,这是共享项目还是平台视图?最后,为什么InverstVisibility不需要名称空间,插件需要在哪里加载/注册/声明?尝试在文档和示例项目中查找此信息,但收效甚微。Docs:Sample:我已经更新了可以将应用程序名称空间作为示例的位置,但是我使用了@casillas在他的问题中使用的XAML来帮助解决他的问题。你需要Nuget软件包,这里有一个例子,说明了如果这没有帮助,如何使用它。我建议你再写一个问题