[英]Create an app with web interface on mobile OS using Xamarin.Forms
Is it possible to create cross-platform a mobile app with a Web-based interface using Xamarin.Forms? 是否可以使用Xamarin.Forms创建具有基于Web的界面的跨平台移动应用程序?
The idea is to create a mobile app using C# Xamarin code-behind and web-based UI. 我们的想法是使用C#Xamarin代码隐藏和基于Web的UI创建移动应用程序。
I know that it is possible to call Java code from javascript using Android WebView. 我知道可以使用Android WebView从javascript调用Java代码。 The question is there are any common techniques for binding Xamarin.Forms WebView (or other web view controls) and C# code-behind for cross-platform development (Android, IOS and Windows)?
问题是有没有任何常见的技术来绑定Xamarin.Forms WebView(或其他Web视图控件)和C#代码隐藏以进行跨平台开发(Android,IOS和Windows)?
Yes, there is. 就在这里。 Create a custom renderer for your webview, add a function to the Navigating event handler, and in that event check the url for your indicator:
为您的webview创建自定义渲染器,向导航事件处理程序添加一个函数,并在该事件中检查指标的URL:
public class CustomWebView : WebView
{
public CustomWebView()
{
Navigating += OnShouldLoad;
}
private void OnShouldLoad(object sender, WebNavigatingEventArgs e)
{
if (!e.Url.StartsWith("runcode") || !e.Url.Contains(":"))
return;
var urlInfo = e.Url.Split(':');
switch (urlInfo[1])
{
This assumes the javascript will send a url in the form "runcode: Command " where Command indicates the action that you want to take. 这假设javascript将以“runcode: Command ”的形式发送一个url,其中Command表示你想要采取的行动。
Finally got instructions of building WebView with possibility to call C# functions. 最后得到了构建WebView的指令,可以调用C#函数。
First common explanation is on official guide for xamarin.forms . 第一个常见的解释是关于xamarin.forms的官方指南 。 And here is GitHub project for such WebViews.
这里是用于此类WebView的GitHub项目 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.