【问题标题】:Pop up a view in Xamarin Android using MVVM model使用 MVVM 模型在 Xamarin Android 中弹出视图
【发布时间】:2015-03-06 17:57:53
【问题描述】:

我知道有弹出视图的示例,我可以并且确实制作了一个弹出窗口/警报对话框。但是我们使用 MVVM 模型并使用 ShowViewModel 方法来显示视图。它必须是那样的。

现在实际情况。我有 2 个屏幕。从屏幕 1(列表视图)我选择一个列表项。我来到屏幕 2。我在屏幕 2 上有一个按钮(提交按钮,而不是导航按钮)。单击它应该会显示一个弹出视图。单击确定应该带我回到屏幕 1(列表视图)。简单的。我创建了一个简单的 popup.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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:padding="50dp">
  <TextView
    android:id="@+id/DialogTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="9dp"
    android:textAppearance="@style/AlertTextAppearance"
    local:MvxBind="Text Title"/>
  <TextView
     android:id="@+id/DialogMessage"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:textAppearance="?android:attr/textAppearanceLarge"
     local:MvxBind="Text Message" />
  <Button
    android:id="@+id/OkBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="OK"
    local:MvxBind="Click OKCommand"
    />


</LinearLayout>

当我点击提交时,我会看到一个完整的活动窗口。我不想要那个。我想要一个与弹出窗口一模一样的小窗口,但有视图。任何帮助,将不胜感激。谢谢。 刚开始使用 MVVM 和 Xamarin 编写 Android 代码。我过去确实使用过 eclipse for Android dev。所以这里就不一样了。

【问题讨论】:

    标签: android mvvm xamarin views popupwindow


    【解决方案1】:

    您可以从 DialogFragment 扩展,然后像这样扩展您的布局

    公共类YourDialog:DialogFragment {

        public override Dialog OnCreateDialog(Bundle savedInstanceState)
        {
            var builder = new AlertDialog.Builder(Activity);
            // Get the layout inflater
            var inflater = Activity.LayoutInflater;
    
            _view = inflater.Inflate(Resource.Layout.your_layout, null);
    
            // Inflate and set the layout for the dialog
            // Pass null as the parent view because its going in the dialog layout
            builder.SetView(_view);
    
    
    
            return builder.Create();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-01
      • 2018-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2011-09-10
      相关资源
      最近更新 更多