the arguments are null
What does this mean? I have done a sample and it worked well.
The xaml:
<VerticalStackLayout>
<WebView HeightRequest="700" Source="">
<WebView.Behaviors>
<toolkit:EventToCommandBehavior
EventName="Navigated"
Command="{Binding IncrementCounterCommand}"/>
</WebView.Behaviors>
</WebView>
<Label Text="{Binding Counter}" HeightRequest="50" BackgroundColor="Red" TextColor="Green" FontSize="Large"/>
</VerticalStackLayout>
The viewmodel:
public class MyViewModel : ObservableObject
{
public MyViewModel()
{
IncrementCounterCommand = new RelayCommand(IncrementCounter);
}
private int counter;
public int Counter
{
get => counter;
private set => SetProperty(ref counter, value);
}
public ICommand IncrementCounterCommand { get; }
private void IncrementCounter() => Counter++;
}
Or you want to add a navigated event in the page.cs, you can try:
In the xaml:
<VerticalStackLayout>
<WebView Navigated="WebView_Navigated" HeightRequest="700" Source=""/>
<Label Text="{Binding Counter}" HeightRequest="50" BackgroundColor="Red" TextColor="Green" FontSize="Large"/>
</VerticalStackLayout>
In the page.cs:
private void WebView_Navigated(object sender, WebNavigatedEventArgs e)
{
//do something
}
In addition, I also tried use them together and found that the navigeted event will execute at first, then the command will execute after it.
Update how to pass the WebNavigatedEventArgs into the view model
In the view model:
public class MyViewModel : ObservableObject
{
public WebNavigatedEventArgs webNavigatedEventArgs;
public MyViewModel()
{
IncrementCounterCommand = new RelayCommand(IncrementCounter);
}
public ICommand IncrementCounterCommand { get; }
private void IncrementCounter() => Navigated(webNavigatedEventArgs);
private async void Navigated(WebNavigatedEventArgs arg)
{
}
}
In the page.cs:
private void WebView_Navigated(object sender, WebNavigatedEventArgs e)
{
var viewmodel = (MyViewModel)this.BindingContext;
viewmodel.webNavigatedEventArgs = e;
}
In the xaml:
<WebView Navigated="WebView_Navigated" HeightRequest="700" Source=">
<WebView.Behaviors>
<toolkit:EventToCommandBehavior
EventName="Navigated"
Command="{Binding IncrementCounterCommand}"/>
</WebView.Behaviors>
</WebView>
But I really don't suggest you do so.