【发布时间】:2020-05-10 02:09:04
【问题描述】:
我的一个 xaml 页面中有一个 webview 和一个标签。我正在将本地 html 文件加载到 OnAppearing() 内的 web 视图中。问题是我看不到标签。 Webview 占据整个屏幕。我在 Android 中测试过。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Test.Views.MyWebView">
<ContentPage.Content>
<StackLayout BackgroundColor="Red" VerticalOptions="FillAndExpand" Orientation="Vertical">
<Label HeightRequest="100" TextColor="Black" Text="Sample"/>
<StackLayout>
<ScrollView>
<other:HybridWebView x:Name="hybridWebView" VerticalOptions="FillAndExpand"
Navigating="webView_Navigating" HeightRequest="400" Navigated="MywebView_Navigated" />
</ScrollView>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
后面的代码
正在出现
protected override void OnAppearing()
{
base.OnAppearing();
NavigationPage.SetHasNavigationBar(this, false);
if (isFirstRun)
{
jsonOutput = JsonConvert.SerializeObject(payData);
//var htmlSource = new HtmlWebViewSource();
var urlSource = new UrlWebViewSource();
string url = DependencyService.Get<IBaseUrl>().Get();
TempUrl = Path.Combine(url, "xamarinhtmlmotor.html");
urlSource.Url = TempUrl;
hybridWebView.Source = urlSource;
isFirstRun = false;
Content = hybridWebView;
}
}
webView_Navigating
private void webView_Navigating(object sender, WebNavigatingEventArgs e)
{
UserDialogs.Instance.ShowLoading("Loading...", MaskType.Black);
}
这里我目前正在检查安卓设备
MywebView_Navigated
private async void MywebView_Navigated(object sender, WebNavigatedEventArgs e)
{
UserDialogs.Instance.HideLoading();
if (Device.RuntimePlatform == Device.Android)
{
if (e.Url.Equals("file:///android_asset/web/xamarinhtmlmotor.html"))
{
getResult();
}
else if (e.Url.Equals("http://localhost/receipt_motor.aspx"))
{
string rtNo = "receiptNo";
string cvNo = "<%= hdntxtbxTaksit.ClientID %>";
receiptNo = await hybridWebView.EvaluateJavaScriptAsync($"document.getElementById('{rtNo}').value;");
cvNoteNo = await hybridWebView.EvaluateJavaScriptAsync($"document.getElementById('{cvNo}');");
if (receiptNo != null && !receiptNo.Equals(""))
{
}
if (cvNoteNo != null && !cvNoteNo.Equals(""))
{
}
}
}
}
}
【问题讨论】:
标签: xamarin.forms