GalaSoft.MvvmLight 的 AppCompatActivityBase 的 Prism 版本是什么?
What is the Prism version of GalaSoft.MvvmLight's AppCompatActivityBase?
我正在将 Xamarin.Android 中支持 GalaSoft.MVVMLight 的应用重写到 Prism。
这个 Android 项目有这个特定的 class GalaSoft.MVVMLight AppCompatActivityBase
继承自 AppCompatActivity
。
public class AppCompatActivityBase : AppCompatActivity
{
public AppCompatActivityBase()
{
}
internal string ActivityKey
{
get;
private set;
}
/// <summary>
/// The activity that is currently in the foreground.
/// </summary>
public static AppCompatActivityBase CurrentActivity
{
get;
private set;
}
internal static string NextPageKey
{
get;
set;
}
/// <summary>
/// If possible, discards the current page and displays the previous page
/// on the navigation stack.
/// </summary>
public static void GoBack()
{
if (CurrentActivity != null)
{
CurrentActivity.OnBackPressed();
}
}
/// <summary>
/// Overrides <see cref="M:Android.App.Activity.OnResume" />. If you override
/// this method in your own Activities, make sure to call
/// base.OnResume to allow the <see cref="T:GalaSoft.MvvmLight.Views.NavigationService" />
/// to work properly.
/// </summary>
protected override void OnResume()
{
CurrentActivity = this;
if (string.IsNullOrEmpty(ActivityKey))
{
ActivityKey = NextPageKey;
NextPageKey = null;
}
base.OnResume();
}
/// <summary>
/// Overrides <see cref="M:Android.App.Activity.OnCreate" />. If you override
/// this method in your own Activities, make sure to call
/// base.OnCreate to allow the <see cref="T:GalaSoft.MvvmLight.Views.NavigationService" />
/// to work properly.
/// </summary>
protected override void OnCreate(Bundle savedInstanceState)
{
// Set CurrentActivity to the first activity that is created
if (CurrentActivity == null)
{
CurrentActivity = this;
if (string.IsNullOrEmpty(ActivityKey))
{
ActivityKey = NextPageKey;
NextPageKey = null;
}
}
base.OnCreate(savedInstanceState);
}
}
此 AppCompatActivityBase 然后在用户首选项中引用 class,如下所示。
class UserPreferences : IUserPreferences
{
const int MaximumHistoryEntries = 5;
readonly ISharedPreferences preferences;
readonly ISharedPreferencesEditor editor;
public UserPreferences()
{
preferences = PreferenceManager.GetDefaultSharedPreferences(AppCompatActivityBase.CurrentActivity.ApplicationContext);
editor = preferences.Edit();
}
public event EventHandler Saved;
public string AssetsExtractedVersion
{
get
{
return preferences.GetString(AppCompatActivityBase.CurrentActivity.GetString(Resource.String.PrefKeyAssetsExtractedVersion), null);
}
set
{
editor.PutString(AppCompatActivityBase.CurrentActivity.GetString(Resource.String.PrefKeyAssetsExtractedVersion), value);
}
}
public void Save()
{
editor.Commit();
Saved?.Invoke(this, EventArgs.Empty);
}
}
因为我的项目现在支持 Prism 而不是 GalaSoft.MVVMLight。如何替换 Prism 中的 AppCompatActivityBase?我的背景是 iOS,所以我无法理解 Xamarin/Prism 的 Android 结尾。
没有一个。虽然 Prism 确实有一个 Android 特定的二进制文件来支持使用 Xamarin.Forms 依赖项解析器的依赖项注入,其中可能包含 Android.Content.Context
,但 Prism 本身完全依赖于 Xamarin.Forms 并运行确切的所有平台都一样。因此,不需要 Prism 特定基础 Activity
我正在将 Xamarin.Android 中支持 GalaSoft.MVVMLight 的应用重写到 Prism。
这个 Android 项目有这个特定的 class GalaSoft.MVVMLight AppCompatActivityBase
继承自 AppCompatActivity
。
public class AppCompatActivityBase : AppCompatActivity
{
public AppCompatActivityBase()
{
}
internal string ActivityKey
{
get;
private set;
}
/// <summary>
/// The activity that is currently in the foreground.
/// </summary>
public static AppCompatActivityBase CurrentActivity
{
get;
private set;
}
internal static string NextPageKey
{
get;
set;
}
/// <summary>
/// If possible, discards the current page and displays the previous page
/// on the navigation stack.
/// </summary>
public static void GoBack()
{
if (CurrentActivity != null)
{
CurrentActivity.OnBackPressed();
}
}
/// <summary>
/// Overrides <see cref="M:Android.App.Activity.OnResume" />. If you override
/// this method in your own Activities, make sure to call
/// base.OnResume to allow the <see cref="T:GalaSoft.MvvmLight.Views.NavigationService" />
/// to work properly.
/// </summary>
protected override void OnResume()
{
CurrentActivity = this;
if (string.IsNullOrEmpty(ActivityKey))
{
ActivityKey = NextPageKey;
NextPageKey = null;
}
base.OnResume();
}
/// <summary>
/// Overrides <see cref="M:Android.App.Activity.OnCreate" />. If you override
/// this method in your own Activities, make sure to call
/// base.OnCreate to allow the <see cref="T:GalaSoft.MvvmLight.Views.NavigationService" />
/// to work properly.
/// </summary>
protected override void OnCreate(Bundle savedInstanceState)
{
// Set CurrentActivity to the first activity that is created
if (CurrentActivity == null)
{
CurrentActivity = this;
if (string.IsNullOrEmpty(ActivityKey))
{
ActivityKey = NextPageKey;
NextPageKey = null;
}
}
base.OnCreate(savedInstanceState);
}
}
此 AppCompatActivityBase 然后在用户首选项中引用 class,如下所示。
class UserPreferences : IUserPreferences
{
const int MaximumHistoryEntries = 5;
readonly ISharedPreferences preferences;
readonly ISharedPreferencesEditor editor;
public UserPreferences()
{
preferences = PreferenceManager.GetDefaultSharedPreferences(AppCompatActivityBase.CurrentActivity.ApplicationContext);
editor = preferences.Edit();
}
public event EventHandler Saved;
public string AssetsExtractedVersion
{
get
{
return preferences.GetString(AppCompatActivityBase.CurrentActivity.GetString(Resource.String.PrefKeyAssetsExtractedVersion), null);
}
set
{
editor.PutString(AppCompatActivityBase.CurrentActivity.GetString(Resource.String.PrefKeyAssetsExtractedVersion), value);
}
}
public void Save()
{
editor.Commit();
Saved?.Invoke(this, EventArgs.Empty);
}
}
因为我的项目现在支持 Prism 而不是 GalaSoft.MVVMLight。如何替换 Prism 中的 AppCompatActivityBase?我的背景是 iOS,所以我无法理解 Xamarin/Prism 的 Android 结尾。
没有一个。虽然 Prism 确实有一个 Android 特定的二进制文件来支持使用 Xamarin.Forms 依赖项解析器的依赖项注入,其中可能包含 Android.Content.Context
,但 Prism 本身完全依赖于 Xamarin.Forms 并运行确切的所有平台都一样。因此,不需要 Prism 特定基础 Activity