如何调用从xamarin.forms平台的特定页面 [英] how to call platform specific page from xamarin.forms
问题描述
我是新来的xamarin应用开发,我有一些问题:
I am new to the xamarin app development, I have some questions :
- 是否有可能调用从特定于平台的页面
Xamarin.Form页? - 我可以从视图模型做页面导航?
让我解释清楚。
我有一个页面 XFView.xaml
, XFView.xaml.cs
和 XFViewModel.cs
从 XFView.xaml.cs
或 XFViewModel.cs
我要打电话 MAActivity.cs
页这是目前在 Xamarin.Andriod
项目
I have a Page XFView.xaml
, XFView.xaml.cs
and XFViewModel.cs
in PCL (Xamarin.Forms) project from XFView.xaml.cs
or XFViewModel.cs
i want to call MAActivity.cs
page which is present in Xamarin.Andriod
project
我尝试了很多,但有得到任何想法。
I tried a lot but got getting any idea.
推荐答案
每当你想调用自天然的东西( MAActivity.cs
你的情况),你必须使用DependencyService。
Whenever you would like to call something from native (MAActivity.cs
in your case), you have to use DependencyService.
例如:
-
设置依存服务
Setup dependency service
// PCL Project
public interface INativePages
{
void StartMA();
}
// MonoDroid Project
[assembly: Dependency(typeof(NativePages))]
public class NativePages : INativePages
{
public void StartMA()
{
var intent = new Intent(Forms.Context, typeof(MAActivity));
Forms.Context.StartActivity(intent);
}
}
援引PCL
Invoke in PCL
// PCL Project
DependencyService.Get<INativePages>().StartMA();
这篇关于如何调用从xamarin.forms平台的特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!