微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin WebView Source 的参数类型是什么?

如何解决Xamarin WebView Source 的参数类型是什么?

我有一个在 XAML 中完全定义的 WebView。它显示来自本地文件的“帮助文件”。它适用于带有 Source="file:///android_asset/Getting Started Text.html" 的 Android。我现在也试图让它在 UWP 上工作,所以我添加OnPlatform,如下所示。我得到:

XFC0009 找不到“源”的属性、BindableProperty 或事件,或者值和属性间的类型不匹配。在 上。

我也试过 x:TypeArguments="x:String" 并得到同样的错误x:TypeArguments 应该用于 Webview.source 吗?

            <WebView  WidthRequest="1000" HeightRequest="1000">
                <WebView.source>
                    <OnPlatform x:TypeArguments="x:Uri">
                        <OnPlatform.Platforms>
                            <On Platform="Android" Value="file:///android_asset/Getting Started Text.html" />
                            <On Platform="UWP" Value="ms-appx-web:///Getting Started Text.html" />
                        </OnPlatform.Platforms>
                    </OnPlatform>
                </WebView.source>
            </WebView>

Windows 10 Pro 64.Xamarin 16.9 上的 VS 2019 16.9.4 社区

解决方法

根据 WebView.Source Property docs WebView.SourceWebViewSource 类型,因此您应该输入 Uri 而不是 stringWebViewSource

    <WebView WidthRequest="1000"
             HeightRequest="1000">
        <WebView.Source>
            <OnPlatform x:TypeArguments="WebViewSource">
                <OnPlatform.Platforms>
                    <On Platform="Android"
                        Value="file:///android_asset/Getting Started Text.html"/>
                    <On Platform="UWP"
                        Value="ms-appx-web:///Getting Started Text.html"/>
                </OnPlatform.Platforms>
            </OnPlatform>
        </WebView.Source>
    </WebView>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。