1. 前提

  • 原本是在大屏上展示系统,系统有个功能是加载第三方的网站,第三方网站按照大屏的分辨率写死了宽高;
  • 现需要改到小屏展示系统,而这个第三方的网站不能随着 WebBrowser 窗口的尺寸调整网站内容的尺寸。

2. 解决思路

1)加载完毕后,调用 InvokeScript 方法执行在当前加载的文档中定义的脚本函数,简单说就是调用网站的 js 方法;

2)网站未必会定义一个实现相关功能的方法,因此我们可以通过 eval 方法执行 js 代码。

<Grid x:Name="wb" Margin="10" Background="White">
<WebBrowser Margin="0" x:Name="wbLeft" Source="about:blank"></WebBrowser>
</Grid>
wbLeft.Width = wb.ActualWidth;
wbLeft.Height = wb.ActualHeight;
string url = string.Empty;
wbLeft.Navigate(url); wbLeft.LoadCompleted += (s,e)=>
{
wbLeft.InvokeScript("eval", new object[] { "document.body.style.zoom = 0.8;" });
};

题外话:

<script type="text/javascript">

eval("x=10;y=20;document.write(x*y)")

document.write(eval("2+2"))

var x=10
document.write(eval(x+17))
</script> 输出
200
4
27

WPF 应用 - 通过 js 缩放 System.Windows.Controls.WebBrowser 的内容的更多相关文章

  1. 用 .NET Reflector 8 查看 System.Windows.Controls 命名空间下的类

    为了学习自定义控件,就想看看WPF基本元素的代码.使用到工具.NET Reflector. System.Windows.Controls 命名空间在PresentationFramework.dll ...

  2. 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1

    在WPF中DataGrid 选择事件中获取SelectedItems 报错如下 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转 ...

  3. System.Windows.Forms.WebBrowser中 处理 js 脚本 window.Open 禁止新建窗口 的方法

    wb 是 拖放在窗体上的 System.Windows.Forms.WebBrowser 在你的窗体代码中定义 SHDocVw.WebBrowser_V1 wb1; 在 你窗体的 load 事件中 加 ...

  4. WPF CoboxItem控件使用SelectedItem去调System.Windows.Controls.ComboBoxItem: 前缀方法

    textComBox.SelectedItem as ComboBoxItem).Content textConbox: 控件Combobox 的Name 在Combobox控件SelectionCh ...

  5. C# System.Windows.Forms.WebBrowser中判断浏览器内核和版本

    参考 [完美]原生JS获取浏览器版本判断--支持Edge,IE,Chrome,Firefox,Opera,Safari,以及各种使用Chrome和IE混合内核的浏览器 利用js来判断 namespac ...

  6. WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常

    WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...

  7. 【C#/WPF】如何查看System.Windows.Interactivity.dll中EventTrigger的EventNames属性有哪些

    WPF项目中,从Nuget搜索并下载System.Windows.Interactivity.dll,安装到项目中,并在XAML界面引入. <UserControl xmlns:i=" ...

  8. 【WPF/WAF】使用System.Windows.Interactivity交互事件

    下载System.Windows.Interactivity.dll文件,并引入项目中(在VS项目的引用列表中可以看到).可在Nuget搜索System.Windows.Interactivity下载 ...

  9. WPF的System.Windows.Threading.DispatcherTimer的使用(每隔一定的时间重复做某事)

    这里使用了一个进度条来展示, 前段代码: <Window x:Class="TimerTest.MainWindow" xmlns="http://schemas. ...

随机推荐

  1. Linux网络文件下载

    wget 以网络下载 maven 包为例 wget -c http://mirrors.shu.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-ma ...

  2. Netty(五)Netty 高性能之道

    4.背景介绍 4.1.1 Netty 惊人的性能数据 通过使用 Netty(NIO 框架)相比于传统基于 Java 序列化+BIO(同步阻塞 IO)的通信框架,性能提升了 8 倍多.事 实上,我对这个 ...

  3. HDU 4335 What is N?(指数循环节)题解

    题意: 询问有多少数\(n\)满足\(n^{n!}\equiv b\mod p \land\ n\in[1,M]\),数据范围:\(M\leq2^{64}-1,p\leq1e5\) 思路: 这题显然要 ...

  4. React Portal All In One

    React Portal All In One react multi root https://reactjs.org/docs/portals.html https://zh-hans.react ...

  5. Vue & Sentry sourcemaps All In One

    Vue & Sentry sourcemaps All In One vue & sentry & sourcemaps https://docs.sentry.io/plat ...

  6. 你所不知道的 JS: null , undefined, NaN, true==1=="1",false==0=="",null== undefined

    1 1 1 === 全相等(全部相等) ==  值相等(部分相等) demo: var x=0; undefined var y=false; undefined if(x===y){ console ...

  7. VIM 官方教程

    VIM 官方教程 zh-hans vim official documents https://www.vim.org/docs.php https://vimhelp.org/ translatio ...

  8. cloud linux cli & dart pub

    cloud linux cli & dart pub https://bcb8313e-05bf-4a93-9309-5f1f68eef1b1.ws-us02.gitpod.io/ https ...

  9. vscode & typescript & optional-chaining bug

    vscode & typescript & optional-chaining bug https://www.cnblogs.com/xgqfrms/p/11745541.html ...

  10. DAPHNE PATEL:有主见的人,才能活出精彩人生

    有主见的人,会活出什么样子呢?近日,NGK灵石团队技术副总裁DAPHNE 女士给出了答案. DAPHNE PATEL表示,有主见的人,才能活出精彩的人生.为什么这么说呢? DAPHNE PATEL用自 ...