[Silverlight 4 RC]WebBrowserBrush概览

时间:2022-04-22
本文章向大家介绍[Silverlight 4 RC]WebBrowserBrush概览,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

上一节介绍了WebBrowser控件,这里就接着WebBrowser介绍下WebBrowserBrush控件。在silverlight 4 beta2时WebBrowserBrush被称为HtmlBrush,他在rc版本被更名为了WebBrowserBrush。

WebBrowserBrush是一种刷子,就好像VideoBrush一样。这里他能绘制出来一些WebBrowser所提供的内容。由于WebBrowser控件的关系,所以它也只能运行在OOB模式下,若是在浏览器中,它将会是一个透明的刷子。

这里注意在WebBrowser内容发生变化后需要调用WebBrowserBrush的Redraw方法。

这里再做一个demo

用Vs2010新建立一个html页面,上边放置一个图片。

xaml:

<grid x:name="LayoutRoot" background="White">
    <webbrowser source="http://localhost:8739/HTMLPage1.htm" x:name="xWebBrowser" height="150" verticalalignment="Top"></webbrowser>
    <textblock canvas.left="5" canvas.top="30" fontfamily="Verdana" fontsize="120" fontweight="Bold" textwrapping="Wrap" text="Html" margin="0,154,0,0" horizontalalignment="Left" verticalalignment="Top" width="400">
    <textblock.foreground>
      <webbrowserbrush x:name="xWebBrowserBrush" sourcename="xWebBrowser" stretch="UniformToFill">
    </webbrowserbrush></textblock.foreground>
    </textblock>
    <button x:name="btnPaint" content="渲染" horizontalalignment="Right" verticalalignment="Bottom" width="75" margin="0,0,8,8" click="btnPaint_Click"></button>
</grid>

c#:

public MainPage()
{
    InitializeComponent();            
}
 
private void btnPaint_Click(object sender, System.Windows.RoutedEventArgs e)
{
    xWebBrowserBrush.Redraw();
}