我需要学习如何绑定和更改元素的属性。
我应该通过点击按钮来改变元素的可见性。
我有一个名为Hello.axml
的文件,其中包含不同的元素。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Strings[VerificationPhoneText]" />
<TextView
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Variable01" />
<Button
android:id="@+id/enterButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
local:MvxBind="Text Strings[EnterButton]; Click ClickCommand" />
<GestureOverlayView
android:layout_height="284dp"
android:layout_width="280dp"
android:background="#FAFAFA"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="114dp"
local:MvxBind="Visibility Visibility(MyProperty)">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World" />
<ImageView
android:src="@mipmap/ic_check_circle_black_48dp"
android:layout_marginLeft="95dp"
android:layout_marginRight="95dp"
android:layout_marginTop="103dp" />
</GestureOverlayView>
我已经安装了Visibility插件:
PM> Install-Package MvvmCross.Plugin.Visibility -Version 5.6.3
我修改了HelloViewModel.cs
文件:
using MvvmCross.Core.ViewModels;
using System.Windows.Input;
namespace My.Project.Core.ViewModels
{
public class HelloViewModel : BaseViewModel
{
private bool _myProperty;
public bool MyProperty
{
get
{
return _myProperty;
}
set
{
_myProperty = value;
RaisePropertyChanged();
}
}
public ICommand ClickCommand => new MvxCommand(() =>
{
MyProperty = !MyProperty;
});
}
}
但我仍然有一个问题——所有元素在开始时都是可见的,按钮不起作用。
更新。
我的HelloView.cs
:
using Android.App;
namespace My.Project.Droid.Views
{
[Activity]
public class HelloView:BaseView
{
protected override int LayoutResource => Resource.Layout.HelloView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
}
}
}
请帮助我学习它!