简体   繁体   English

使用Xamarin.Forms在移动操作系统上创建带有Web界面的应用程序

[英]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将以“runco​​de: 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.

相关问题 如何使用JSON元素在Xamarin.Forms中创建用户界面 - How to create a User Interface in Xamarin.Forms using JSON Element 移动架构:基于Xamarin:如何创建以数据为中心的移动应用程序? (例如,使用Xamarin.Forms / REST)? - Mobile-Architecture: Based on Xamarin: How to create a data-centric mobile app? (e.g. with Xamarin.Forms/REST)? 使用xamarin.forms的iOS应用程序链接 - App links for iOS using xamarin.forms 如何修复xamarin.forms移动应用页面中的空列表视图 - How to fix an empty listview in xamarin.forms mobile app page 在VS 2017中使用“使用xamarin.forms创建移动应用程序”电子书 - using “creating mobile apps with xamarin.forms” ebook with VS 2017 在xamarin.forms中的应用内购买 - In App Purchase in xamarin.forms 如何在Xamarin.Forms中创建类似于Facebook应用程序的标签页 - How to create tabbed page in Xamarin.Forms similar to that of Facebook app Xamarin.Forms中Xaml中的Device.OS - Device.OS in Xaml in Xamarin.Forms 如何使用xamarin.forms在弹出窗口中创建表单? - How to create a form in a pop-up using xamarin.forms? 如何使用 OxyPlot 在 Xamarin.Forms 便携式应用程序中创建图表? - How to Create Charts in Xamarin.Forms Portable Application using OxyPlot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM