因为您使用的是 WebBrowser 控件而不是WPF,所以您必须依赖磁盘来加载您在步骤 4 中提到的 CSS 文件。解决此问题的唯一方法是使用Resource Hacker之类的工具来加载“非托管”资源并使用res ://协议 ( http://msdn.microsoft.com/en-us/library/aa767740(VS.85).aspx ) 用于一些真正的 Microsoft 1990 年代怀旧。
您仍然需要将数据放入 HTML 元素中。下面的代码示例可能有助于回答一些问题:
void WireUpBrowserEvents()
{
HtmlElement table = this._browser.Document.GetElementById( "UnitFormsTable" );
if ( table != null )
{
HtmlElementCollection thead = table.GetElementsByTagName( "thead" );
if ( ( thead != null ) && ( thead.Count == 1 ) )
{
HtmlElementCollection links = thead[0].GetElementsByTagName( "a" );
if ( ( links != null ) && ( links.Count > 0 ) )
{
foreach ( HtmlElement a in links )
{
a.Click += new HtmlElementEventHandler( XslSort_Click );
}
}
}
}
}
void XslSort_Click( object sender, HtmlElementEventArgs e )
{
e.ReturnValue = false;
if ( this._xslSortWorker.IsBusy ) return;
if ( sender is HtmlElement )
{
HtmlElement a = sender as HtmlElement;
this._browser.Hide();
this._browserMessage.Visible = true;
this._browserMessage.Refresh();
this._xslSortWorker.RunWorkerAsync( a.Id );
}
}
您可能已经知道 HtmlElement 和 HtmlElementCollection 位于 System.Windows.Forms 命名空间中。这些评论可能没有帮助,但我试过了:)