任何MvxPreferenceFragment示例代码



我的设置似乎无法在android上运行。有没有展示如何使用MvxPreferenceFragment的示例?我主要缺少一种显示Fragment的方式,比如MvxPreferenceActivity

遗憾的是,Android的样本没有使用它。

https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/Samples/Example.Droid/Resources/layout/fragment_settings.axml

我确实在"正常"活动(MvxCachingFragmentCompatActivity)中尝试过,但应用程序只是崩溃了。

我的碎片代码:

[MvxFragment(typeof(SettingsViewModel), Resource.Id.flContent, true)]
[Register("client.android.fragments.SettingsFragment")]
public class SettingsFragment : MvxPreferenceFragment<SettingsSyncViewModel>
{
    public override void OnCreatePreferences(Bundle p0, string p1)
    {
        // Load the preferences from an XML resource
        AddPreferencesFromResource(Resource.Xml.preferences);
    }
}

preferences.xml:

<?xml version="1.0" encoding="utf-8" ?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  <PreferenceCategory
        android:title="Category Title"
        android:key="pref_key_storage_settings">
    <CheckBoxPreference
        android:key="pref_sync"
        android:title="CheckboxStuff"
        android:summary="Checkbox..."
        android:defaultValue="true" />
    <Preference
                android:key="pref_key_limit"
                android:summary="Stuff ..."
                android:title="Hello World" />
  </PreferenceCategory>
</PreferenceScreen>

视图模型为空。只是想把它展示出来。有什么建议吗?

我认为这是我们应该在演示程序中解决的问题。我目前所做的是从Android项目中打开这个:

//ViewModel is loaded here to support popup fragments
private PreviewViewModel previewViewModel;
public PreviewViewModel ViewModel => previewViewModel = previewViewModel ?? Mvx.IocConstruct<PreviewViewModel>();

public void ShowDetail()
{
   var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity as MvxCachingFragmentCompatActivity;
   if (activity != null)
   {
     var dialog = new PreviewDialogFragment() { DataContext = ViewModel };
     dialog.Show(activity.SupportFragmentManager, "preview");
   }
}

相关内容

  • 没有找到相关文章

最新更新