bslein
bslein

Reputation: 332

MvvmCross Android Binding String Array

I'm trying to bind a single dimension string array Property to a TextView but it doesn't work.

ViewModel:

    public string[] Player
    {
        get { return _player; }
        set { _player = value; RaisePropertyChanged(() => Player); }
    }

Windows8 xaml (which works perfect):

<TextBox x:Name="txtbox_PlayerName1" Text="{Binding Path=Player[0], Mode=TwoWay}" Grid.Column="2" Width="600" Height="30" HorizontalAlignment="Left"></TextBox>

Android axml:

<TextView
    android:layout_marginTop="20dp"
    android:layout_marginLeft="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView1"
    local:MvxBind="Text Player[0]" />

Log:

MvxBind:Warning:103,21 Unable to bind: source property source not found IndexedProperty:0 on String[] 01-14 12:17:26.419 I/mono-stdout(28171): MvxBind:Warning:103,21 Unable to bind: source property source not found IndexedProperty:0 on String[]

I tried different syntax for Binding with no success. Also i tried to bind a string Property of a "Player" Object like Players[0].PlayerName which worked fine in XAML but not with Android.

https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/ApiExamples/ApiExamples.Droid/Resources/Layout/Test_ObservableCollection.axml It's working in the API Samples from Mvvmcross (with an Observable Collection, i tried the same thing with no success)

Upvotes: 4

Views: 615

Answers (1)

bslein
bslein

Reputation: 332

I tried to make a List with PlayerModel instead of an array with PlayerModel. I'm binding the Property PlayerName of PlayerModel instead of an string array and it work's now. Im confused because i also tried that a few days ago.

private List<PlayerModel> _player;

public List<PlayerModel> Player
    {
        get { return _player; }
        set { _player = value; RaisePropertyChanged(() => Player); }
    }

xaml:

Text="{Binding Path=Player[0].PlayerName, Mode=TwoWay}"

axml:

<TextView
android:layout_marginTop="20dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
local:MvxBind="Text Player[0].PlayerName" />

Upvotes: 2

Related Questions