mvvmcross绑定不适用于android弹出窗口

时间:2018-08-14 12:26:01

标签: c# mvvm xamarin.android mvvmcross

我正在使用 xamarin 运行android本机应用程序,并且正在使用 mvvmcross 框架。我的应用程序运行良好,但是它只是 Android的弹出窗口,未绑定到viewmodel

下面是我的代码-

弹出窗口的Contentview-

departmentpopupmenulist.axml

<?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:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <FrameLayout
        android:layout_width="match_parent"
        android:id="@+id/departmentpopupview"
        android:layout_height="match_parent">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginRight="40dp"
            android:layout_marginTop="35dp"
            android:id="@+id/deptpopupbtncancel"
            android:background="@drawable/customer_popup_cancel" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="70dp"
            android:orientation="vertical">
            <SearchView
                android:id="@+id/deptpopupsearch_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:iconifiedByDefault="false"
                android:layout_gravity="center_horizontal"
                local:MvxBind="Text SearchDepartmentParam" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="50dp"
                android:orientation="horizontal">
                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <MvxListView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        local:MvxBind="ItemClick CategorySelectedCommand"
                        android:id="@+id/mvxLVDeptList" />
                    <LinearLayout
                        android:id="@+id/side_index_departmentList"
                        android:layout_width="20dp"
                        android:layout_height="fill_parent"
                        android:orientation="vertical"
                        android:layout_gravity="right"
                        android:background="@color/gray"
                        android:layout_marginTop="10dp" />
                </FrameLayout>
            </LinearLayout>
        </LinearLayout>
    </FrameLayout>
</LinearLayout>

单击按钮即会打开部门弹出窗口。代码如下-

private void OpenDeptMenu_Click(object sender, EventArgs evtArgs)
{
    PopupWindow popupWindow = new PopupWindow(this);
    View llFragment_layout = this.BindingInflate(Resource.Layout.departmentpopupmenulist, null);
    ListView lvDept = (ListView)llFragment_layout.FindViewById(Resource.Id.mvxLVDeptList);
    ImageButton ibCancel = (ImageButton)llFragment_layout.FindViewById(Resource.Id.deptpopupbtncancel);
    ibCancel.Click += delegate {
        if (string.IsNullOrEmpty(tvSubDepartmentProductList.Text))
        {

        }
        popupWindow.Dismiss();
    };
    departmentAdapter= new DepartmentAdapter(this.ApplicationContext, Resource.Id.tvItemName, ViewModel.DepartmentViewModel.DepartmentWithHeader.ToList());
    lvDept.Adapter = departmentAdapter;
    lvDept.NestedScrollingEnabled = true;
    lvDept.ItemClick += LvDept_ItemClick;
    popupWindow.ContentView = llFragment_layout;
    popupWindow.SoftInputMode = SoftInput.AdjustNothing;
    popupWindow.Focusable = true;
    Drawable drawable = this.GetDrawable(Resource.Drawable.departmentlistbackground);
    popupWindow.SetBackgroundDrawable(drawable);
    popupWindow.Height = drawable.IntrinsicHeight;
    popupWindow.Width = drawable.IntrinsicWidth;
    popupWindow.OutsideTouchable = false;
    popupWindow.Touchable = true;
    popupWindow.ShowAsDropDown(ibDepartment, 0, -80, GravityFlags.Right);
    LinearLayout linearLayoutSideIndex = llFragment_layout.FindViewById<LinearLayout>(Resource.Id.side_index_departmentList);
    displayIndexDept(linearLayoutSideIndex);
}

我的Viewmodel具有属性SearchDepartmentParam,如下所示。。 此Viewmodel继承自MvxViewModel,并且它的其他属性绑定到其控件。只是弹出窗口的searchview不绑定到viewmodel。

public string SearchDepartmentParam
{
    get { return _searchDepartmentParam; }
    set
    {
        _searchDepartmentParam = value;
        RaisePropertyChanged(() => SearchDepartmentParam);
        FilteredDepartmentResults();

    }
}

0 个答案:

没有答案