3

我尝试使用 EventToCommandBehavior,如下例所示:

https://github.com/dotnet-architecture/eShopOnContainers/blob/dev/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/EventToCommandBehavior.cs

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/behaviors/reusable/event-to-command-behavior/

问题是未设置 Command 可绑定属性。我发现很多关于类似问题的文章,但没有一篇能解决我的问题。有没有人有类似的问题?

我的命令行为类事件是 1 : 1,就像在第一个 url 中一样。

我的观点:

<AbsoluteLayout
    VerticalOptions="FillAndExpand" 
    HorizontalOptions="FillAndExpand"
    IsVisible="True">
    <WebView 
        AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
        AbsoluteLayout.LayoutFlags="All"
        Source ="{Binding WebViewSource}">
        <WebView.Behaviors>
            <behaviors:EventToCommandBehavior
                            EventName="Navigating"
                            EventArgsConverter="{StaticResource WebNavigatingEventArgsConverter}"
                            Command="{Binding OnWebViewNavigatingCommand}" />
        </WebView.Behaviors>
    </WebView>
</AbsoluteLayout>

视图模型的片段:

    public ICommand OnWebViewNavigatingCommand => new Command<string>(async (url) => await OnWebViewNavigatingAsync(url));

    private async Task OnWebViewNavigatingAsync(string url)
    {
        // Logic
    }
4

0 回答 0