我想阻止Awesomium中的某些图片出现在页面上。此代码不能工作,因为Awesomium IResourceInterceptor不是一个类,它是一个接口。
public class ResourceInterceptor : IResourceInterceptor
{
public bool NoImages { get; set; }
private static string[] _imagesFileTypes = { ".png", ".jpg", ".jpeg", ".gif", ".bmp" };
public ResourceResponse OnRequest(ResourceRequest request)
{
string ext = System.IO.Path.GetExtension(request.Url.ToString()).ToLower();
if (NoImages && _imagesFileTypes.Contains(ext))
{
request.Cancel();
}
return null;
}
public bool OnFilterNavigation(NavigationRequest request)
{
return false;
}}
当一个IResourceInterceptor是一个接口时,如何修改它的IResourceInterceptor方法?
发布于 2014-08-22 09:44:27
您可以编写自己的接口实现。接口描述实现接口的类上可用的方法。因此,您可以编写实现IResourceInterceptor接口的自己的类,并像这样使用它:
在构造函数中,与往常一样:
WebCore.Initialized += WebCoreInitialzed;
//create an instance of your Interceptor (you need a private field of course)
interceptor = new ResourceInterceptor();在这种情况下,手持器功能:
private void WebCoreInitialzed(object sender, CoreStartEventArgs e)
{
WebCore.ResourceInterceptor = interceptor;
}如果您不熟悉接口的概念,您可能需要阅读msdn文章这里。
这里可以找到一个可以列出某些教程的接口堆栈溢出问题。
https://stackoverflow.com/questions/25343775
复制相似问题