禁用微调器的选择

时间:2017-01-20 22:33:47

标签: android xamarin.android mvvmcross

如何禁用微调器的选择

<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:textColor="@color/primary_text"   
  local:MvxItemTemplate="@layout/spinner_template"
  local:MvxBind="ItemsSource StudentList; ItemSelected StudentType" />

2 个答案:

答案 0 :(得分:1)

试试这个:

<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
  android:id=@+id/spinner1
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:textColor="@color/primary_text"   
  android:enabled="false"
  android:clickable="false"
  local:MvxItemTemplate="@layout/spinner_template"
  local:MvxBind="ItemsSource StudentList; ItemSelected StudentType" />

要启用,请在您的活动/片段中尝试此操作。

  MvxAppCompatSpinner spinner1 = (MvxAppCompatSpinner)findViewById(R.id.spinner1);
  spinner1.setEnabled(true);
  spinner1.setClickable(true);

答案 1 :(得分:1)

您可以直接绑定到Spinner上的Enabled属性:

local:MvxBind="ItemsSource StudentList; ItemSelected StudentType; Enabled IsEnabled"

任何其他公共财产也是如此。虽然它们中的大部分都是OneWay绑定,但在这种情况下并不重要。

您的ViewModel属性看起来像任何其他属性:

private bool _isEnabled;
public bool IsEnabled
{
    get { return _isEnabled; }
    set { SetProperty(ref _isEnabled, value); }
}

然后当您需要启用/禁用控件时:

IsEnabled = true;