Код: Выделить всё
internal class WebViewNavigatingBehavior : Behavior
{
public static readonly BindableProperty CommandProperty =
BindableProperty.Create(nameof(Command), typeof(IRelayCommand), typeof(WebViewNavigatingBehavior),null,BindingMode.TwoWay);
public IRelayCommand Command
{
get => (IRelayCommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
protected override void OnAttachedTo(WebView bindable)
{
base.OnAttachedTo(bindable);
bindable.Navigating += OnNavigating;
}
protected override void OnDetachingFrom(WebView bindable)
{
base.OnDetachingFrom(bindable);
bindable.Navigating -= OnNavigating;
}
private void OnNavigating(object? sender, WebNavigatingEventArgs e)
{
Application.Current?.Dispatcher.Dispatch(() =>
{
Command?.Execute(e);
});
}
}
< /code>
и в модели представления у меня есть этот код: < /p>
[RelayCommand]
public void MapNavigation(WebNavigatingEventArgs e)
{
double latitude = 0;
double longitude = 0;
if (e.Url.StartsWith("js://coords"))
{
e.Cancel = true;
var uri = new Uri(e.Url);
var query = QueryHelpers.ParseQuery(uri.Query);
if (query.TryGetValue("lat", out var lat) && query.TryGetValue("lng", out var lng))
{
double.TryParse(lat, out latitude);
double.TryParse(lng, out longitude);
//Console.WriteLine($"Reçu : lat={lat}, lng={lng}");
}
}
Client.Latitude = latitude;
Client.Longitude = longitude;
Console.WriteLine($"Latitude : {Client.Latitude}, Longitude : {Client.Longitude} , NumTel: {Client.NumTel}");
}
< /code>
В моем представлении: < /p>
Подробнее здесь: https://stackoverflow.com/questions/795 ... to-the-com