wp7 webbrowser 添加依赖属性content

前端之家收集整理的这篇文章主要介绍了wp7 webbrowser 添加依赖属性content前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

using@H_404_7@@H_404_7@ Microsoft.Phone.Controls;

@H_404_7@@H_404_7@

using@H_404_7@@H_404_7@ System;

@H_404_7@@H_404_7@

using@H_404_7@@H_404_7@ System.Windows;

@H_404_7@@H_404_7@

namespace@H_404_7@@H_404_7@ CommonUI.AttachedProperty

@H_404_7@@H_404_7@

{

@H_404_7@@H_404_7@ /// <summary>

@H_404_7@@H_404_7@

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

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// </summary>

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ public@H_404_7@@H_404_7@ class@H_404_7@@H_404_7@ WebBrowserContentBinding

@H_404_7@@H_404_7@

{

@H_404_7@@H_404_7@ /// <summary>

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// attached property Content

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// </summary>

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ public@H_404_7@@H_404_7@ static@H_404_7@@H_404_7@ readonly@H_404_7@@H_404_7@ DependencyProperty@H_404_7@@H_404_7@ ContentProperty = DependencyProperty@H_404_7@@H_404_7@.RegisterAttached("Content"@H_404_7@@H_404_7@,typeof@H_404_7@@H_404_7@(string@H_404_7@@H_404_7@),typeof@H_404_7@@H_404_7@(WebBrowserContentBinding@H_404_7@@H_404_7@),new@H_404_7@@H_404_7@ Property@R_301_338@data@H_404_7@@H_404_7@(OnContentChanged));

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// <summary>

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// Get value of attached property Content

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// </summary>

@H_404_7@@H_404_7@

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

@H_404_7@@H_404_7@

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

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ public@H_404_7@@H_404_7@ static@H_404_7@@H_404_7@ string@H_404_7@@H_404_7@ GetContent(WebBrowser@H_404_7@@H_404_7@ obj)

@H_404_7@@H_404_7@

{

@H_404_7@@H_404_7@ return@H_404_7@@H_404_7@ (string@H_404_7@@H_404_7@)obj.GetValue(ContentProperty);

@H_404_7@@H_404_7@

}

@H_404_7@@H_404_7@ /// <summary>

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// Set the value of attached property Content

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ /// </summary>

@H_404_7@@H_404_7@

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

@H_404_7@@H_404_7@

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

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ public@H_404_7@@H_404_7@ static@H_404_7@@H_404_7@ void@H_404_7@@H_404_7@ SetContent(WebBrowser@H_404_7@@H_404_7@ obj,string@H_404_7@@H_404_7@ content)

@H_404_7@@H_404_7@

{

obj.SetValue(ContentProperty,content);

}

@H_404_7@@H_404_7@ private@H_404_7@@H_404_7@ static@H_404_7@@H_404_7@ void@H_404_7@@H_404_7@ OnContentChanged(DependencyObject@H_404_7@@H_404_7@ d,DependencyPropertyChangedEventArgs@H_404_7@@H_404_7@ e)

@H_404_7@@H_404_7@

{

@H_404_7@@H_404_7@ var@H_404_7@@H_404_7@ webBrowser = d as@H_404_7@@H_404_7@ WebBrowser@H_404_7@@H_404_7@;

@H_404_7@@H_404_7@

@H_404_7@@H_404_7@ if@H_404_7@@H_404_7@ (webBrowser == null@H_404_7@@H_404_7@)

@H_404_7@@H_404_7@

{

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

@H_404_7@@H_404_7@

}

webBrowser.LoadCompleted += WebBrowser_LoadCompleted;

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

}

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

@H_404_7@@H_404_7@

{

@H_404_7@@H_404_7@ var@H_404_7@@H_404_7@ wb = sender as@H_404_7@@H_404_7@ WebBrowser@H_404_7@@H_404_7@;

@H_404_7@@H_404_7@

wb.LoadCompleted -= WebBrowser_LoadCompleted;

@H_404_7@@H_404_7@ wb.Visibility = Visibility@H_404_7@@H_404_7@.Visible;

@H_404_7@@H_404_7@

}

}

}

猜你在找的设计模式相关文章