Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android MvxSpinner selecteditem未在项目资源更改时更新_Android_Xamarin_Mvvmcross - Fatal编程技术网

Android MvxSpinner selecteditem未在项目资源更改时更新

Android MvxSpinner selecteditem未在项目资源更改时更新,android,xamarin,mvvmcross,Android,Xamarin,Mvvmcross,我正在构建一个表单,其中包括从列表中添加项目,但显示给用户的列表取决于从另一个列表中进行的选择。为此,我有两个MVXSpinner,每个都有一个绑定的ItemsSource和SelectedItem <MvxSpinner android:layout_width="300dp" android:layout_height="50dp" local:MvxBind="ItemsSource item_source_one; SelectedItem selected_it

我正在构建一个表单,其中包括从列表中添加项目,但显示给用户的列表取决于从另一个列表中进行的选择。为此,我有两个MVXSpinner,每个都有一个绑定的ItemsSource和SelectedItem

<MvxSpinner
   android:layout_width="300dp"
   android:layout_height="50dp"
   local:MvxBind="ItemsSource item_source_one; SelectedItem selected_item_one;"/>
<MvxSpinner
   android:layout_width="300dp"
   android:layout_height="50dp"
   local:MvxBind="ItemsSource item_source_two; SelectedItem selected_item_two;"/>


selected\u item\u one
更改
item\u source\u two
更改为新列表时。所有这些都有效,除非
item\u source\u two
更改
selected\u item\u two
与更改前保持不变。我希望
selected\u item\u two
item\u source\u two
更改时显示的内容相匹配。

微调器绑定在MvvmCross中并不完美-尤其是
SelectedItem
更改必须在
ItemsSource
更改之后发送

要解决此问题,您可以在
项源
之后发出假
SelectedItem
更改-例如:

 RaisePropertyChanged(() => item_source_two);
 RaisePropertyChanged(() => selected_item_two);
public class MySpinner : MvxSpinner
{
    public MySpinner(Context context, IAttributeSet attrs)
        : base(context, attrs)
    {
    }

    [MvxSetToNullAfterBinding]
    public new IEnumerable ItemsSource
    {
        get { return base.ItemsSource; }
        set 
        { 
            // TODO - work out what the current selection and store it in a local variable
            base.ItemsSource = value; 
            // TODO - reset the current selection here from the local variable
        }
    }
}
<>如果你想更全面地解决这个问题,你也可以考虑重写MVXSPIN——很遗憾,你不能轻易继承,因为我们错过了Virtual,但是你做了一些类似的事情:

 RaisePropertyChanged(() => item_source_two);
 RaisePropertyChanged(() => selected_item_two);
public class MySpinner : MvxSpinner
{
    public MySpinner(Context context, IAttributeSet attrs)
        : base(context, attrs)
    {
    }

    [MvxSetToNullAfterBinding]
    public new IEnumerable ItemsSource
    {
        get { return base.ItemsSource; }
        set 
        { 
            // TODO - work out what the current selection and store it in a local variable
            base.ItemsSource = value; 
            // TODO - reset the current selection here from the local variable
        }
    }
}

继承自

我不得不这样做

public class MySpinner : MvxSpinner
{
   public MySpinner(Context context, IAttributeSet attrs):base(context,attrs)
{
}

[MvxSetToNullAfterBinding]
public new IEnumerable ItemsSource
{
    get { return base.ItemsSource; }
    set 
    { 
       base.ItemsSource = null;            
       base.ItemsSource = value;     
    }
}
}
之后,该集合将在您键入时更新!:)