xamarin WebView导航方法获取对象

时间:2019-07-19 15:47:58

标签: xamarin xamarin.forms webview

我在ItemTemplate控件内部有一个WebView控件,并希望将ID传递给ProgramNameWebView_Navigating方法,以便我可以更新单击链接的数据库。我试图将ID添加到ClassId并在后端看到它,但是我看不到它。

  

还有其他属性可以将值设置为该属性并在事件的后端看到它吗?

xaml

<Grid  Grid.Row="0"  Grid.Column="0">
   <WebView HorizontalOptions="FillAndExpand" HeightRequest="{StaticResource webviewHeight}" Navigating="ProgramNameWebView_Navigating"  ClassId="{Binding AssetItem.AssetId}"  x:Name="ProgramNameWebView">
      <WebView.Source>
        <HtmlWebViewSource Html="{Binding AssetItem.Description}"/>
      </WebView.Source>
  </WebView>
</Grid>

c#

 private void ProgramNameWebView_Navigating(object sender, WebNavigatingEventArgs e)
        {
            if (e.Url.StartsWith("http") || (DeviceInfo.Platform == DevicePlatform.Android && e.Url.StartsWith("mailto:")))
            {
                string Key = "UserType";
                string UserType = Barrel.Current.Get<string>(key: Key);
                var tracking = new Tracking
                {
                    DeviceType = string.Format("{0} - {1}", DeviceInfo.Platform.ToString(), DeviceInfo.Idiom.ToString()),
                    DeviceModel = DeviceInfo.Model.ToString(),
                   // AssetId = Asset.AssetId,
                    UserType = UserType,
                    Logdate = DateTime.Now
                };
                var ts = new TrackingService();
                var result = ts.SetTracking(tracking);
                var uri = new Uri(e.Url);
                Device.OpenUri(uri);
                e.Cancel = true;
            }
        }

0 个答案:

没有答案