我正在尝试在Visual Studio中创建一个绑定类,就像在Android Studio https://developer.android.com/topic/libraries/data-binding/generated-binding中一样
我拥有的:
Visual Studio 2022 17.4.5版本
赛马林17.4
我所做的:
1.创建Android应用程序(Xamarin)项目。空白应用程序和最低Android版本10.0
1.安装Xamarin.AndroidX.DataBinding.ViewBindingwww.example.com核心包 7.4.0.1 nuget package
1.添加到. csproj文件
<AutoGenerateLayoutBindings>true</AutoGenerateLayoutBindings>
1.将根元素添加到activity_main. xml
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/hello_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, world!"
android:textSize="24sp"
android:layout_centerInParent="true" />
</RelativeLayout>
</layout>
1.生成项目。在输出窗口中
Rebuild started...
1>------ Rebuild All started: Project: App4, Configuration: Debug Any CPU ------
Restored C:\Users\koly8\source\repos\App4\App4.csproj (in 73 ms).
1> App4 -> C:\Users\koly8\source\repos\App4\bin\Debug\App4.dll
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
未创建任何内容
可能漏掉了什么
1条答案
按热度按时间v9tzhpje1#
我测试了你提供的代码,但失败,然后参考文档:Data Binding Library,上面写着:
要将您的应用配置为使用数据绑定,请在app模块的
build.gradle
文件中启用dataBinding
构建选项,如下例所示:dataBinding库实际上是gradle构建工具包的一部分,因此在Xamarin.Android应用程序中不可用。对于xamarinandroid,最推荐的使用数据绑定的方法是使用原生库,例如MVVMCross。