我在MvvmCross中找到了一个很好的博客文章,但是我想在MvvmCross Monodroid.Dialog应用程序中使用它。有没有人设法让这个工作?
我的行动中有以下内容:
Root = new RootElement{
new Section{
new ViewElement("page_home_view")
}
};
并确保page_home_view.axml
和item_menu.axml
位于布局文件夹中。
但是我收到以下错误:
[Android.Dialog] Inflate failed: Didn't find class "Mvx.MvxListView" on path: /data/app/SomeApp.Mobile.Droid-1.apk
[Android.Dialog] ViewElement: Failed to load resource: page_home_view
目前我只想在布局中打开一个对话框,以便我可以添加所有功能。
为什么不知道MvxListView
是什么?
以下是视图的完整XML:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" /> <!-- The navigation drawer -->
<Mvx.MvxListView
local:MvxBind="ItemsSource MenuItems; ItemClick SelectMenuItemCommand"
local:MvxItemTemplate="@layout/item_menu"
android:id="@+id/left_drawer"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:choiceMode="singleChoice"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111" /> </android.support.v4.widget.DrawerLayout>
[更新]
好的,所以我不能从monodroid.dialog mvvmcross活动中调用SetContentView(Resource.Layout.page_home_view);
。
我现在在对话活动中有以下内容:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate (bundle);
//SetContentView(Resource.Layout.page_home_view);
var bindings = this.CreateInlineBindingTarget<CategoriesViewModel>();
Root = new RootElement{
new BindableSection<CustomViewElement>(string.Empty, () => new CustomViewElement(this))
.Bind(bindings, element => element.ItemsSource, vm => vm.Categories),
};
this.ActionBar.SetDisplayHomeAsUpEnabled(false);
this.ActionBar.SetHomeButtonEnabled (true);
var view = this.BindingInflate (Resource.Layout.page_home_view, null);
this._drawer = view.FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
this._drawerList = view.FindViewById<MvxListView>(Resource.Id.left_drawer);
_drawer.SetDrawerShadow(Resource.Drawable.drawer_shadow_dark, (int)GravityFlags.Start);
this._drawerToggle = new MyActionBarDrawerToggle(this, _drawer,
Resource.Drawable.ic_drawer_light,
Resource.String.drawer_open,
Resource.String.drawer_close);
//You can alternatively use _drawer.DrawerClosed here
this._drawerToggle.DrawerClosed += delegate
{
//this.ActionBar.Title = this._title;
this.InvalidateOptionsMenu();
};
//You can alternatively use _drawer.DrawerOpened here
this._drawerToggle.DrawerOpened += delegate
{
//this.ActionBar.Title = this._drawerTitle;
this.InvalidateOptionsMenu();
};
_drawer.SetDrawerListener(this._drawerToggle);
}
然而没有任何东西被连线......
单击操作栏中的按钮不会执行任何操作。
答案 0 :(得分:0)
您是否忘记定义本地名称空间?
xmlns:local="http://schemas.android.com/apk/res-auto"
确保在XML文件的根节点中定义XML名称空间,请参阅下面的示例:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">