加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

wp7 webbrowser 添加依赖属性content

发布时间:2020-12-13 23:15:03 所属栏目:百科 来源:网络整理
导读:using Microsoft.Phone.Controls; using System; using System.Windows; namespace CommonUI.AttachedProperty { /// summary /// Atttached property for WebBrowser control,bind a html string to display as web page in web browser /// /summary publi

using Microsoft.Phone.Controls;

using System;

using System.Windows;

namespace CommonUI.AttachedProperty

{

/// <summary>

/// Atttached property for WebBrowser control,bind a html string to display as web page in web browser

/// </summary>

public class WebBrowserContentBinding

{

/// <summary>

/// attached property Content

/// </summary>

public static readonly DependencyProperty ContentProperty = DependencyProperty.RegisterAttached("Content",typeof(string),typeof(WebBrowserContentBinding),new PropertyMetadata(OnContentChanged));

/// <summary>

/// Get value of attached property Content

/// </summary>

/// <param name="obj">WebBrowser object</param>

/// <returns>the value of Content property </returns>

public static string GetContent(WebBrowser obj)

{

return (string)obj.GetValue(ContentProperty);

}

/// <summary>

/// Set the value of attached property Content

/// </summary>

/// <param name="obj">WebBrowser object</param>

/// <param name="content">the value that set to property Content</param>

public static void SetContent(WebBrowser obj,string content)

{

obj.SetValue(ContentProperty,content);

}

private static void OnContentChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)

{

var webBrowser = d as WebBrowser;

if (webBrowser == null)

{

throw new InvalidOperationException(string.Format("WebBrowserContentBinding attached property only can be used in WebBrowser,you are using in {0}",d.GetType().Name));

}

webBrowser.LoadCompleted += WebBrowser_LoadCompleted;

webBrowser.NavigateToString(e.NewValue.ToString());

}

private static void WebBrowser_LoadCompleted(object sender,System.Windows.Navigation.NavigationEventArgs e)

{

var wb = sender as WebBrowser;

wb.LoadCompleted -= WebBrowser_LoadCompleted;

wb.Visibility = Visibility.Visible;

}

}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读