从一个用户条目中搜索3个网页(Xamarin表单)

时间:2018-10-07 05:02:23

标签: forms url xamarin browser

我有四个选项卡式页面(Amazon,Google和eBay),而最后一个是我的主页。主页上有一个用户条目,下面带有一个搜索按钮。我想同时在所有三个网页(选项卡式页面)上搜索用户输入。无论如何,是否要将“输入/输入”传递给其他三个页面的url?例如“(-)+(用户输入)”。例如,如果有人想购买一台新笔记本电脑,则第一页将接受输入并将其添加到每个页面的URL中。 ....本质上,其他两个选项卡式页面的webview =(“ https://www.google.com/” +笔记本电脑)依此类推。希望我能很好地解释我的问题!预先谢谢大家!!!!

====这是我的主页。Xaml====

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App2.HomePage"             
             Title="Home">

    <ContentPage.Content>
        <StackLayout>
            <Label Text="Home Page"
                VerticalOptions="StartAndExpand" 
                HorizontalOptions="CenterAndExpand"/>
            <Entry x:Name="search1" VerticalOptions="Fill" 
             HorizontalOptions="Fill"/>
            <Button Clicked="Button_Clicked_1" Text="Search" 
             VerticalOptions="Fill" HorizontalOptions="Center"/>
            <Entry x:Name="sms" VerticalOptions="FillAndExpand" 
             HorizontalOptions="Fill"/>
            <Button Clicked="Button_Clicked"
                    Text="Send Text" HorizontalOptions="Center"/>
        </StackLayout>
   </ContentPage.Content>
</ContentPage>

===这是我的HomePage.Xaml.cs ===

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace App2
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class HomePage : ContentPage
    {
        public HomePage()
        {
            InitializeComponent();
        }

        public void Button_Clicked(object sender, EventArgs e)
        {
            string text = sms.Text;
        }

        public void Button_Clicked_1(object sender, EventArgs e)
        {
            string text = search1.Text;
        }
    }
}

===这是我的Google.xaml ===

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App2.Views.Google"
            xmlns:Content="clr-namespace:App2.Views.HomePage"
             Title="Google">
    <StackLayout>

        <StackLayout Orientation="Horizontal">

            <Button Text="&lt;" HeightRequest="40" WidthRequest="45" 
             Clicked="Back_Clicked"/>
            <Button Text="&gt;"    HeightRequest="40" WidthRequest="45" 
             Clicked="Forward_Clicked"/>
            <Entry  x:Name="URL" WidthRequest="197"/>
            <Button Text="Go"  HeightRequest="40" WidthRequest="55" 
             Clicked="Go_Clicked"/>

        </StackLayout>

        <Label x:Name="LoadingLabel" IsVisible="False"/>
        <WebView x:Name="Googlepage" HeightRequest="1000" 
         WidthRequest="1000"/>

    </StackLayout>
</ContentPage>

===这是我的Google.xaml.cs ===

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using App2.Views;
using Xamarin.Forms;

using Xamarin.Forms.Xaml;

namespace App2.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Google : ContentPage
    {
        public Google()
        {
            InitializeComponent();
            URL.Text = ("https://www.google.com/");
            Googlepage.Source = "URL.Text";
        }

        private void Back_Clicked(object sender, EventArgs e)
        {
            if (Googlepage.CanGoBack)
                Googlepage.GoBack();
        }

        private void Forward_Clicked(object sender, EventArgs e)
        {
            if (Googlepage.CanGoForward)
                Googlepage.GoForward();
        }
        private void Go_Clicked(object sender, EventArgs e)
        {
            Googlepage.Source = URL.Text;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

当然还有其他方法可以实现,但是想到的一种方法是包含搜索文本的静态变量。然后,当用户单击每个选项卡式页面时,即在该页面加载时,只需执行特定的搜索URL,包括静态变量中的搜索文本即可。