gpt4 book ai didi

c# - MvvmCross Android 绑定(bind)字符串数组

转载 作者:太空狗 更新时间:2023-10-29 13:15:49 25 4
gpt4 key购买 nike

我试图将一维字符串数组属性绑定(bind)到 TextView,但它不起作用。

View 模型:

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

Windows8 xaml(完美运行):

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

安卓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]" />

日志:

MvxBind:Warning:103,21 无法绑定(bind):在 String[] 上找不到源属性源 IndexedProperty:001-14 12:17:26.419 I/mono-stdout(28171): MvxBind:Warning:103,21 无法绑定(bind):在 String[] 上找不到源属性源 IndexedProperty:0

我尝试了不同的绑定(bind)语法,但没有成功。我还尝试绑定(bind)“Player”对象的字符串属性,例如 Players[0].PlayerName,它在 XAML 中运行良好,但在 Android 中运行不佳。

https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/ApiExamples/ApiExamples.Droid/Resources/Layout/Test_ObservableCollection.axml它在 Mvvmcross 的 API 示例中工作(使用 Observable 集合,我尝试了同样的事情但没有成功)

最佳答案

我尝试用 PlayerModel 创建一个列表,而不是用 PlayerModel 创建一个数组。我正在绑定(bind) PlayerModel 的 Property PlayerName 而不是字符串数组,它现在可以工作了。我很困惑,因为我几天前也试过了。

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}"

XML:

<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" />

关于c# - MvvmCross Android 绑定(bind)字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34788366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com