Skip to content

Nukepayload2/VbWinUI3Demos

Repository files navigation

VB WinUI 3 Demos

Demonstrates how to use WinUI 3 in Visual Basic .NET projects.

Progress

  • No C# or C++ projects for startup
  • Load XamlControlsResources from Microsoft.UI.Xaml.Controls automatically
  • Use a custom Sub Main - You can enable high DPI, add dynamic dependencies or add reg-free WinRT support by editing Program.vb.
  • Allow Windows Forms integration, such as registering HostServices.VBHost at startup
  • Make sure Mica and Acrylic are working as expected on Windows 11
  • Workaround blocking bugs of the WinUI 3 XAML compiler - Generate Xbf files and VB source files
  • Run apps without MSIX packaging
  • Workaround trivial bugs of the WinUI 3 XAML compiler - Generate 99% correct VB source files
  • Publish a NuGet package that contains VB specific build transitive files, so any VB projects will be able to use WinUI 3 without editing *.vbproj manually.
  • Publish a VSIX to add VB WinUI 3 templates to Visual Studio.
  • Write a new VB application framework for WinUI 3 - Allow users to delete Program.vb and use events to configure the App in the Application class
  • Write a new VB "My extension" for WinUI 3 - Enable My.* for WinUI 3 specific things

Environment

  • Visual Studio 2022 with Windows Desktop and UWP development workloads
  • Windows 10 21H2 or Windows 11

How does it work

Approach 1: Use the default WinUI VB XAML compiler

The MSBuild target files of WinUI 3 need some hacking to support Visual Basic. VB projects need to import the following target file to use WinUI 3.

WinUI3.VisualBasic.targets

<Project>

  <PropertyGroup>
    <!-- Workaround for conflicts with WPF -->
    <ImportFrameworkWinFXTargets>true</ImportFrameworkWinFXTargets>
    <!-- Workaround for wrong entry point code generated by WinUI 3 -->
    <DefineConstants>DISABLE_XAML_GENERATED_MAIN</DefineConstants>
  </PropertyGroup>

  <!-- Workaround for XamlPreCompile compilation errors -->
  <Target Name="SpecifyVBRuntimeForXamlPreCompile" BeforeTargets="XamlPreCompile">
    <PropertyGroup>
      <VBRuntime>None</VBRuntime>
    </PropertyGroup>
  </Target>
  
</Project>

Approach 2: Use the WinUI C# XAML compiler and code converter

Stopped with error. See XamlLanguageConverter.

Approach 3: Use a custom XAML compiler

WIP. See Custom XAML compiler.

Samples

BatchFfmpegWinUI

A mp4 video to h265 transcoder.

It converts .mp4 and .mkv videos to h265 encoding by calling H265.bat.

Status

✅ Finished. Tested with WinUI3 v1.3.230602002 and .NET SDK v7.0.7.

How to use it

  • Install ffmpeg to %programfiles%\ffmpeg\bin. If you have installed it in a different location, please add it to %PATH%.
  • Open BatchFfmpegWinUI.sln with Visual Studio.
  • Set BatchFfmpegWinUI_Pack as startup project and run.
  • Drag and drop .mp4 or .mkv files.
  • Press the "Convert" button and wait.

XamlLanguageConverter

Demonstrates how to use MSBuild extension points to invoke the C# XAML compiler and start a code converter to convert the C# output to VB.

Status

❌ Stopped with error. Because it has severe performance issues.

Custom XAML compiler

Use the XamlCompilerTaskPath MSBuild property to replace the path of Microsoft.UI.Xaml.Markup.Compiler.dll with a custom XAML compiler.

The build artifacts won't be published until Microsoft supports building Microsoft.UI.Xaml.Markup.Compiler.dll from source.

Status

⚠ I've modified the VB code template files to fix the following problems. But I'm unable to verify and compile them.

  • Fixed the generated entry point
  • Page generator: Fixed element.IsBindingFileRoot in Output_GetBindingConnectorCase
  • Page generator: Fixed TryGetBindingObject in VectorChanged_*

WinUIGallery

A VB version of WinUIGallery v1.1. It uses the C# XAML converter until the official VB WinUI3 XAML converter works correctly.

Status

WIP, depends on XamlLanguageConverter.

About

Demos for WinUI 3 in Visual Basic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages