MvxSpinner selecteditem在项目源更改中未更新 [英] MvxSpinner selecteditem not updated on itemssource change
问题描述
我正在构建一个涉及从列表中添加项目的表单,但是向用户显示的列表取决于从另一个列表中进行选择.为此,我有两个MvxSpinners,每个MvxSpinners具有绑定的ItemsSource和SelectedItem.
I am building a form that involves adding items from a list, but the list that is being shown to the user depends on the selection from another list. To do this I have two MvxSpinners each with a bound ItemsSource and 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_item_one
更改时,item_source_two
更改为新列表.所有这些工作均有效,但更改item_source_two
时selected_item_two
保持与更改前相同.我希望selected_item_two
匹配item_source_two
更改时在视觉上显示的内容.
When selected_item_one
changes item_source_two
changes to a new list. All of this works, except when item_source_two
is changed selected_item_two
remains the same as it was before the change. I would like for the selected_item_two
to match what is visually shown when item_source_two
changes.
推荐答案
微调器绑定在MvvmCross中并不完美-特别是,必须在ItemsSource
更改后发送SelectedItem
更改.
The spinner binding isn't perfect in MvvmCross - in particular, the SelectedItem
change must be sent after the ItemsSource
change.
要解决此问题,您可以在ItemsSource
之后 处发出伪造的SelectedItem
更改信号-例如像这样:
To work around this, you could signal a fake SelectedItem
change after the ItemsSource
- e.g. something like:
RaisePropertyChanged(() => item_source_two);
RaisePropertyChanged(() => selected_item_two);
如果您想更全面地解决此问题,还可以考虑覆盖MvxSpinner-遗憾的是,由于我们错过了虚拟,因此您无法轻易继承,但是您可以执行以下操作:
If you wanted to fix this more fully, you could also consider overriding MvxSpinner - sadly you can't easily inherit because we missed virtual, but you do something like:
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
}
}
}
这篇关于MvxSpinner selecteditem在项目源更改中未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!