MvvMCross 绑定到 Android 布局中的

2023-12-28

是否可以绑定一个对象X到 include 标签,以便包含的布局中的绑定上下文是X?我想多次使用布局,但不在列表中。

MainLayout.xml

...
<include
    android:id="@+id/btnDealerMap"
    android:layout_width="64dp"
    android:layout_height="64dp"
    android:visibility="gone"
    layout="@layout/ServiceBarButtonPhone" 
    local:MvxBind="??? X" />
...

ServiceBarButtonPhone.xml

Title and Text是的属性X.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res/..."
    android:layout_width="96dp"
    android:layout_height="96dp">
    <TextView
        ...
        android:id="@+id/txtTitle"
        local:MvxBind="Text Title" />
    <TextView
        ...
        android:id="@+id/txtText"
        local:MvxBind="Text Text" />
</RelativeLayout>

外面没有什么可以绑定的include- 但您可以将普通绑定放在文件内部 - 然后它会在编译时包含在其中。请参阅以下示例:https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/ApiExamples/ApiExamples.Droid/Resources/Layout/Test_If.axml https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/ApiExamples/ApiExamples.Droid/Resources/Layout/Test_If.axml

相反,如果您想要一个具有自己的内部“布局”DataContext, try MvxView- 有关示例,请参阅MvxFrameControl- 用于 N=26 的部分 - 参见https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/blob/b405eef7dddf4d65b00116e142855653eae9f06b/N-26-Fraggle/Rock.Droid/Resources/Layout/FirstView.axml https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/blob/b405eef7dddf4d65b00116e142855653eae9f06b/N-26-Fraggle/Rock.Droid/Resources/Layout/FirstView.axml

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MvvMCross 绑定到 Android 布局中的 的相关文章

随机推荐