我尝试设置设计数据,以便在Xamarin Forms Previewer中显示它们。我有一个DesignTimeViewModelLocator:
MessagingCenter.Send(this, "Invoke", "Invokedtrue");
MessagingCenter.Subscribe<MyPage, string>(this, "Invoke", async (sender, arg) =>
{
await Process(arg);
});
MessagingCenter.Unsubscribe<MyPage>(this,"Invoke");
**ListPage**
private void ViewCell_Tapped(object sender, EventArgs e)
{
try
{
MessagingCenter.Send(this, "Invoke", "Invokedtrue");
}
catch (Exception ex)
{
Debug.Write(ex);
}
}
**Detail Page**
MessagingCenter.Subscribe<ListPage, string>(this, "Invoke", async (sender, arg) =>
{
await Process(arg);
});
private async Task Process(string arg)
{
//Here is api call to view detail of particular record
//Here I unsubscribe the MessagingCenter.
MessagingCenter.Unsubscribe<ListPage>(this,"Invoke");
}
还有一个DesignTime视图模型:
public static class DesignTimeViewModelLocator
{
static DesignTimeAboutViewModel aboutVm;
public static DesignTimeAboutViewModel AboutVm => aboutVm ?? (aboutVm = new DesignTimeAboutViewModel());
}
在页面中:
public class DesignTimeAboutViewModel : IAboutViewModel
{
public DesignTimeAboutViewModel()
{
Resources = new LocalizedResources(typeof(Strings), CultureInfo.CurrentUICulture);
}
/// <inheritdoc />
public LocalizedResources Resources { get; }
public MvxAsyncCommand GoToWebsiteCommand { get; }
public MvxAsyncCommand SendMailCommand { get; }
public MvxCommand RateAppCommand { get; }
public MvxAsyncCommand GoToRepositoryCommand { get; }
public MvxAsyncCommand GoToTranslationProjectCommand { get; }
public MvxAsyncCommand GoToDesignerTwitterAccountCommand { get; }
public MvxAsyncCommand GoToContributionPageCommand { get; }
public string Version { get; } = "0.4.5";
public string Website { get; } = "www.foo.ch";
public string SupportMail { get; } = "foo@me.ch";
}
但是视图不会显示任何非静态的内容,例如运行应用程序时可以运行的版本:
我必须进行其他设置吗?