【问题标题】:Why won't Xamarin Forms Webview binding refresh on iOS?为什么 Xamarin Forms Webview 绑定不会在 iOS 上刷新?
【发布时间】:2019-04-01 08:52:50
【问题描述】:

我正在使用 WebView 并构建自己的 html。我想将 webview 绑定到表单上其他地方的更改。这是我的 xaml:

        <WebView HorizontalOptions="FillAndExpand"
                 VerticalOptions="FillAndExpand" 
                 Margin="0">
            <WebView.Source>
                <HtmlWebViewSource x:Name="WebViewSoruce1" Html="{Binding Description}"/>
            </WebView.Source>
        </WebView>

这是我的描述模型代码:

    public string Description
    {
        get {
            return _description;
        }
        set
        {
            _description = value;
            RaisePropertyChanged();
        }
    }

这适用于 Android,但不适用于 iOS。任何建议将不胜感激。

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.ios


    【解决方案1】:

    所以如果其他人遇到这个问题。这就是最终在 iOS 和 Android 上对我有用的方法。

    我必须作为 WebViewSource 绑定到它的 Source 属性,而不是绑定到 HTML。这是我的 XAML:

    <WebView HorizontalOptions="FillAndExpand"
                     VerticalOptions="FillAndExpand" 
                     Margin="0"  Source="{Binding WebViewSource}"/>
    

    在我的视图模型中,我有两个属性。一个绑定 HTML 更改,我将其命名为 Description。另一个是绑定到 WebViewSource。

    下面是代码:

        public HtmlWebViewSource WebViewSource
        {
            get
            {
                return new HtmlWebViewSource { Html = _description };
            }
        }
    
        public string Description
        {
            get {
                return _description;
            }
            set
            {
                _description = value;
                RaisePropertyChanged();
                RaisePropertyChanged("WebViewSource");
            }
        }
    

    这对我有用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    • 2020-05-08
    • 2017-06-26
    • 1970-01-01
    • 2019-06-30
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多