Xlabs ExtendedPicker SelectedItem属性不绑定

时间:2016-03-13 11:16:26

标签: xaml mvvm binding xamarin.forms xlabs

我在项目中使用此控件,无法获取属性绑定。

我的xaml代码:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1221 Incorrect usage of UNION and ORDER BY' in C:\xampp\htdocs\bookstore\filter.php:105 Stack trace: #0 C:\xampp\htdocs\bookstore\filter.php(105): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\bookstore\filter.php on line 105

我的ViewModel代码:

   <controls:ExtendedPicker x:Name="myPicker" ItemsSource="{Binding ListaLugaresTrabajo}" DisplayProperty="NombreLugar" SelectedItem="{Binding SelectedLugarTrabajo}" />

我的模型代码(也使用sqlite):

private ObservableCollection<LugarDeTrabajo> _listaLugaresTrabajo;

    public ObservableCollection<LugarDeTrabajo> ListaLugaresTrabajo {
        get {
            return _listaLugaresTrabajo;
        }
        set {
            _listaLugaresTrabajo = value;
            RaisePropertyChanged (() => ListaLugaresTrabajo);
        }
    }

    private LugarDeTrabajo _selectedLugarTrabajo;

    public LugarDeTrabajo SelectedLugarTrabajo {
        get {
            return _selectedLugarTrabajo;
        }
        set {
            _selectedLugarTrabajo = value;
            RaisePropertyChanged (() => SelectedLugarTrabajo);
        }
    }

ItemsSource和DisplayProperty工作正常,但SelectedItem始终为null。

我使用MvvmCross框架,在其他应用程序中正常工作。

这是一个共享项目,我正在尝试Android版本。

那可能会发生什么?

解决方案: 将SelectedItem属性设置为TwoWay绑定模式。

更正Xaml代码:

[Table ("LugaresDeTrabajo")]
public class LugarDeTrabajo
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [Unique]
    public string NombreLugar { get; set; }
}

2 个答案:

答案 0 :(得分:3)

根据ExtendedPicker source code SelectedItem,bindable属性的默认绑定模式设置为OneWay。这意味着ViewModel中的更改会反映在View中,但不会反过来。

如果您需要将更改从ViewModel传播到View,反之亦然,请按以下方式设置SelectedItem属性:

SelectedItem="{Binding SelectedLugarTrabajo, Mode=TwoWay}" 

如果您希望仅通过以下方式将更改从View传播到ViewModel设置SelectedItem

SelectedItem="{Binding SelectedLugarTrabajo, Mode=OneWayToSource}" 

答案 1 :(得分:0)

您还可以依赖x = [1, 2, 4, 8]; D = []; for k=x; A1 = 1./x; D = [D A1]; end 属性。 这是一个例子:

SelectedIndexChanged
相关问题