-
-
Notifications
You must be signed in to change notification settings - Fork 175
嵌入WPF WinForm
Henry edited this page Sep 10, 2019
·
1 revision
使用HTML和CSS来做界面的确是比较方便,即做一些很好的效果也相对比较容易,特别现有的HTML5技术;但如果传统的UI技术来做就比较麻烦和工作量大了。对于.NET来说通过webBrowser再结合HTML和CSS就非常容易制作应用界面了,但前提是需要在应用中集成HTTP服务。组件提供netstandard2.0支持,可以轻松把组件的功能集成在WinForm或WPF桌面程序中。
private BeetleX.FastHttpApi.HttpApiServer mHttpApiServer;
private void Form1_Load(object sender, EventArgs e)
{
mHttpApiServer = new BeetleX.FastHttpApi.HttpApiServer();
mHttpApiServer.Register(typeof(Form1).Assembly);
mHttpApiServer.Open();
} "HttpConfig": {
"Host": "",
"Port": 12345,
"SSL": false,
"CertificateFile": "",
"CertificatePassword": "",
"MaxBodyLength": 20097152,
"OutputStackTrace": true,
"StaticResurceType": "xml;svg;woff;woff2;jpg;jpeg;gif;png;js;html;htm;css;txt;ico;zip;rar",
"DefaultPage": "index.html;index.htm",
"NotLoadFolder": "\\Files;\\Images;\\Data",
"NoGzipFiles": "xml;svg;woff;woff2;jpg;jpeg;gif;png;js;html;htm;css;txt;ico;zip;rar",
"CacheFiles": "",
"BufferSize": 8192,
"WebSocketMaxRPS": 2000,
"WriteLog": true,
"LogToConsole": true,
"LogLevel": "Warring"
}
配置内容可以根据实际情况的需要来设置,以上配置默认配置是在端口12345上开启http和websocket服务;运行程序后可以通过浏览器访问http://localhost:12345即可访问服务.
可以根据需求来制订相关内容
静态文件属性设置成嵌入程序或编译复制的方式进行发布,程序可以在webBrowser设置服务地址即可打开网页,效果如下:
如果使用内嵌的http给合html``css``vue做桌面应用开发,那必然也需要有数据交互的接口;接下来简单地定义一个接口让javascript访问
[Controller]
public class WebAction
{
public object GetStarted(string email)
{
return new TextResult($"{email} {DateTime.Now}");
}
}只需要在项目中简单地添加一个控制器即可,以上GetStarted访问的访问路径是/GetStarted通过ajax在页面调用的脚本
function GetStarted(email) {
$.get('/GetStarted?email=' + email, function (result) {
alert(result);
});
}完整示例代码 https://github.com/IKende/FastHttpApi/tree/master/samples/WinWebSample



