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



我有四个选项卡式页面(亚马逊,谷歌和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>

===这是我的主页.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;
}
}
}

===这是我的谷歌.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>

===这是我的谷歌.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;
}
}
}

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

最新更新