Creating a WinUI control library
A control library is a great way to reuse your WinUI controls across projects, much in the same way that .NET libraries enable projects to share business logic. This concept is not new to WinUI; you can create control libraries for most UI frameworks. We are going to create a control library with a user control containing two WinUI controls:
- A
TextBox
to enter a URL where our users want thatWebView2
to navigate - A reload
Button
to reload the current web page inWebView2
We will use one event to trigger the reload and another to notify the host that a new URL has been entered:
- Start by adding a new Control Library (WinUI in Desktop) project to the solution in your language of choice. Name the project
WebViewBrowser.Controls
. - Remove Class1.cs from the project and use Add | New Item to add a new User Control (WinUI) named
BrowserToolbar
to the project.Note
A User Control is best suited to our needs here. We want to define...