FSC_WebUIFramework 2.1.0
See the version list below for details.
dotnet add package FSC_WebUIFramework --version 2.1.0
NuGet\Install-Package FSC_WebUIFramework -Version 2.1.0
<PackageReference Include="FSC_WebUIFramework" Version="2.1.0" />
paket add FSC_WebUIFramework --version 2.1.0
#r "nuget: FSC_WebUIFramework, 2.1.0"
// Install FSC_WebUIFramework as a Cake Addin #addin nuget:?package=FSC_WebUIFramework&version=2.1.0 // Install FSC_WebUIFramework as a Cake Tool #tool nuget:?package=FSC_WebUIFramework&version=2.1.0
FSC.WUF
FSC - Web UI Framework - A simple, but great way to design modern applications for windows in C#
What is WUF?
WUF is short and means Web UI Framework. This framework is based on WPF and the webview2. This library makes it possible to use HTML and CSS instead of XAML. It is important to not forget, that this is not a website. Yes, you load html and css, but javascript is blocked. Instead of JavaScript, there is a JS - C# bridge with a lot of methods to use. It works really well.
Easy style - modern style
The library includes bootrap 5 by default. So if you don't have any experience in CSS, you are able to use all bootstrap features.
Custom CSS support
Yes, custom CSS is supported. It can be used by appending a css resource to the head.
Loading one site at once
No, this doesn't work. It is different to a normal website. For example the input tags and others that work like that, may not end without a slash.
- <input> wrong.
- <input /> right. As it is visible, the library has some special rules. Same as loading the "page". You are not able to load one big HTML file. There is a limit of 2 MB. To load bigger content, make an index.html as your default site and load with innerHtml, append or prepend the content into the body or into other elements.
Reloading? Bye bye
Yes, it's true. What ever happens, this library will not reload the view. Everything works dynamic with C#. You need a table? Add one per html resource. You want to add a table row? Sure, add it per html resource. It is very easy to use.
The program does not work and will there be Html and Css files next to the exe and dll builds?
No, don't worry. You need to set all files that you want to use as an embedded resource. After compiling, they will not be visible from the outside. There is almost no visible difference to a normal program.
How to start a project?
It works with every .Net6 and .Net7 project. The recommend way is the following:
- Start a .Net6|7 console project
- Go to the project properties and change the application type from console to windows application
- Start writing the code ...
Code example C#
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
namespace FSC.WUF.TEST
{
internal class Program
{
[STAThread] // <- This is important
static void Main(string[] args)
{
var window = WindowManager.Create((WindowManager window) => Run(window), new Size(300, 300));
Application application = new Application();
application.Run();
}
static Action<WindowManager> Run = (WindowManager window) =>
{
var html = new Html();
html.Load("index.html");
window.ShowIcon = Visibility.Collapsed;
window.ResizeMode = ResizeMode.CanResize;
window.Background = new SolidColorBrush(Color.FromRgb(33, 37, 41));
window.Titlebar = new WindowTitlebar
{
Background = new SolidColorBrush(Color.FromRgb(33, 37, 41)),
Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255))
};
window.Load(html);
window.OnLoaded += async (s, e) =>
{
await window.AddEventListener(".btn-primary", "click", async (HtmlDocument element) =>
{
var input = await window.GetElement("input").Value();
input = input.Trim('"');
if (string.IsNullOrWhiteSpace(input))
{
MessageBox.Show("Enter a name please ...");
return;
}
MessageBox.Show("Hello " + input);
});
await window.AddEventListener(".btn-secondary", "click", (HtmlDocument element) =>
{
MessageBox.Show("Please use login ...");
});
var css = new Css();
css.Load("test.css");
await window.GetElement("head").Append(css);
window.OnPopup += (s, e) => Process.Start(new ProcessStartInfo(e?.Link) { UseShellExecute = true });
};
};
}
}
Code example Html
This html file is a demo. Normally you should split it up into multiple html files, otherwise your file could become larger than 2 MB
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body class="bg-dark">
<div class="container">
<h1 class="text-white h1 mt-3">Login</h1>
<p class="text text-white">
Please login to use our services
</p>
<form>
<div class="input-group flex-nowrap my-2">
<span class="input-group-text" id="addon-wrapping">@</span>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping"/>
</div>
<div class="input-group flex-nowrap my-2">
<span class="input-group-text" id="addon-wrapping">*</span>
<input type="password" disabled="disabled" class="form-control" placeholder="Password" aria-label="Username" aria-describedby="addon-wrapping"/>
</div>
<div class="w-100">
<button id="unique-btn" class="btn btn-primary float-end">Login</button>
<button class="btn btn-secondary mx-2 float-end">Register</button>
</div>
<a href="https://google.com">Click here >Google<</a>
</form>
</div>
</body>
</html>
Code example Css
h1 {
background-image: url("res://test.png"); // Even here you can set resources per res url
background-size: auto 100%;
}
Bindings are great and new in 2.1
Let's take a small look at them
Program.cs
namespace FSC.WUF.TEST
{
internal class Program
{
[STAThread]
static void Main(string[] args)
{
var window = WindowManager.Create((WindowManager window) => Run(window), new Size(600, 500));
Application application = new Application();
application.Run();
}
static Action<WindowManager> Run = (WindowManager window) =>
{
var html = new Html();
html.Load("index.html");
window.ShowIcon = Visibility.Collapsed;
window.ResizeMode = ResizeMode.CanResize;
window.Background = new SolidColorBrush(Color.FromRgb(33, 37, 41));
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Titlebar = new WindowTitlebar
{
Background = new SolidColorBrush(Color.FromRgb(33, 37, 41)),
Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255))
};
window.Load(html);
window.OnLoaded += async (s, e) =>
{
var people = new List<Person>();
var person1 = new Person {
Id = 0,
FirstName = "Jack",
LastName = "Exampleman",
Age = 30,
};
var person2 = new Person {
Id = 1,
FirstName = "Timmy",
LastName = "Lalala",
Age = 16,
};
var person3 = new Person {
Id = 2,
FirstName = "Cindy",
LastName = "Stone",
Age = 25,
};
people.Add(person1);
people.Add(person2);
people.Add(person3);
var html = new Html();
html.Load("table_row.html");
html.Bind(people);
await window.GetElement(".people").Append(html);
};
};
}
}
index.html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Table Binding</title>
</head>
<body class="bg-dark">
<table class="table table-dark table-striped">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">First name</th>
<th scope="col">Last name</th>
<th scope="col">Age</th>
</tr>
</thead>
<tbody class="people">
</tbody>
</table>
</body>
</html>
table_row.html
<tr>
<th scope="row">@Binding->Id;</th>
<td>@Binding->FirstName;</td>
<td>@Binding->LastName;</td>
<td>@Binding->Age;</td>
</tr>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0-windows was computed. |
-
net6.0-windows7.0
- Microsoft.Web.WebView2 (>= 1.0.1462.37)
-
net7.0-windows7.0
- Microsoft.Web.WebView2 (>= 1.0.1462.37)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
New years update
Happy new year. The end of 2022 brings you a new feature as a surprise.
Bindings. Now you kind bind a class or a list / array of the class to an html file