Skip to content

Commit

Permalink
Merge pull request #853 from Caliburn-Micro/feature/WinUI
Browse files Browse the repository at this point in the history
Initial implementation of WinUI with samples and features working
  • Loading branch information
KasperSK authored Jan 11, 2025
2 parents ee84233 + 5b49477 commit d644b15
Show file tree
Hide file tree
Showing 125 changed files with 2,679 additions and 203 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ jobs:
run: msbuild ${{env.caliburn_features}} -t:restore

- name: Build feature features
run: msbuild ${{env.caliburn_features}} /t:Build /p:Configuration=${{env.build_configuration}}
run: msbuild ${{env.caliburn_features}} /t:Build /p:Configuration=Debug

- name: Pack Nuget
run: msbuild ${{env.caliburn_sln}} /t:package /p:Configuration=${{env.build_configuration}}

- name: publish Nuget Packages to GitHub
run: dotnet nuget push ${{env.nuget_upload}} --source ${{env.package_feed}} --api-key ${{secrets.PUBLISH_NUGET_PACKAGE}} --skip-duplicate
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request'
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ MyGet | [![MyGet Package](https://img.shields.io/myget/caliburn-micro-builds/v/c
NuGet | [![NuGet Package](https://img.shields.io/nuget/v/Caliburn.Micro.svg?logo=nuget&logoColor=white&&style=for-the-badge&colorB=green)](https://www.nuget.org/packages/Caliburn.Micro)
GitHub Action | ![example workflow](https://github.com/Caliburn-Micro/Caliburn.Micro/actions/workflows/dotnet.yml/badge.svg)

Caliburn.Micro is a small, yet powerful framework, designed for building applications across all XAML platforms. With strong support for MVVM and other proven UI patterns, Caliburn.Micro will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
Caliburn.Micro is a small, yet powerful framework, designed for building applications across all XAML platforms. With strong support for MVVM and other proven UI patterns, Caliburn.Micro enables you to build your solution quickly without sacrificing code quality or testability.

## Packages are available on Nuget
- [Caliburn.Micro.Core](https://www.nuget.org/packages/Caliburn.Micro.Core/) - The Portable Class Library (PCL) portion of Caliburn.Micro.
- [Caliburn.Micro.Core](https://www.nuget.org/packages/Caliburn.Micro.Core/) - The Standard Class Library portion of Caliburn.Micro.
- [Caliburn.Micro](https://www.nuget.org/packages/Caliburn.Micro/) - The platform-specific adapters for Caliburn.Micro.
- [Caliburn.Micro.Xamarin.Forms](https://www.nuget.org/packages/Caliburn.Micro.Xamarin.Forms/) - Support to Caliburn.Micro in Xamarin.Forms.

## Packages are available on Github
- [Caliburn.Micro.Core](https://github.com/Caliburn-Micro/Caliburn.Micro/pkgs/nuget/Caliburn.Micro.Core) - The Portable Class Library (PCL) portion of Caliburn.Micro.
- [Caliburn.Micro.Core](https://github.com/Caliburn-Micro/Caliburn.Micro/pkgs/nuget/Caliburn.Micro.Core) - The Standard Class Library portion of Caliburn.Micro.
- [Caliburn.Micro](https://github.com/Caliburn-Micro/Caliburn.Micro/pkgs/nuget/Caliburn.Micro) - The platform-specific adapters for Caliburn.Micro.
- [Caliburn.Micro.Xamarin.Forms](https://github.com/Caliburn-Micro/Caliburn.Micro/pkgs/nuget/Caliburn.Micro.Xamarin.Forms) - Support to Caliburn.Micro for Xamarin.Forms.
- [Caliburn.Micro.Maui](https://github.com/Caliburn-Micro/Caliburn.Micro/pkgs/nuget/Caliburn.Micro.Maui) - Support to Caliburn.Micro for dotnet Maui
- [Caliburn.Micro.Avalonia](https://github.com/Caliburn-Micro/Caliburn.Micro/pkgs/nuget/Caliburn.Micro.Avalonia) - Support To Caliburn.Micro for Avalonia UI
- [Caliburn.Micro.WinUI]() - Support to Caliburn.Micro for WinUI (WinApp Sdk) Coming Soon
- [Caliburn.Micro.WinUI]() - Support to Caliburn.Micro for WinUI (WinApp Sdk)

## Questions
- For non bug related questions see [Stack Overflow](https://stackoverflow.com/questions/tagged/caliburn.micro)
Expand Down
14 changes: 7 additions & 7 deletions samples/features/Features.Avalonia/Features.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.2" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.2" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.2.2" />
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.2.3" />

<PackageReference Include="Avalonia.Themes.FLuent" Version="11.2.2" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.1" />
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.2.0.1" />
<PackageReference Include="Avalonia.Themes.FLuent" Version="11.2.3" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.7" />
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.2.0.7" />
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.6.1" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.2" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="Caliburn.Micro.Avalonia">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using Caliburn.Micro;
#if XAMARINFORMS
using Xamarin.Forms;
Expand Down Expand Up @@ -51,6 +52,22 @@ public override async void Execute(CoroutineExecutionContext context)
await dialog.ShowAsync();
OnCompleted();
}
#elif WinUI3
public override async void Execute(CoroutineExecutionContext context)
{
var dialog = new MessageDialog(_content, _title);

var hWnd = GetActiveWindow();

WinRT.Interop.InitializeWithWindow.Initialize(dialog, hWnd);

await dialog.ShowAsync();

OnCompleted();
}

[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
#else
public override async void Execute(CoroutineExecutionContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#if SILVERLIGHT || WPF
using System.Windows;
using System.Windows.Controls;
#elif WinUI3
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#elif AVALONIA
using Avalonia.Controls;
#else
Expand Down
4 changes: 2 additions & 2 deletions samples/features/Features.UWP/Features.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>Features.CrossPlatform</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.20348.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -272,4 +272,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
20 changes: 20 additions & 0 deletions samples/features/Features.WinUI3/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<cal:CaliburnApplication
x:Class="Features.WinUI3.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Features.WinUI3"
xmlns:cal="using:Caliburn.Micro">
<Application.Resources>
<ResourceDictionary >
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
<ResourceDictionary>
<SolidColorBrush x:Key="BackgroundBrush" Color="#FF225378" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</cal:CaliburnApplication>
114 changes: 114 additions & 0 deletions samples/features/Features.WinUI3/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using Caliburn.Micro;
using Features.CrossPlatform.ViewModels;
using Features.CrossPlatform.Views;
using Features.WinUI3.Views;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel.Activation;
using Windows.UI.Popups;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Features.WinUI3
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : CaliburnApplication
{
private WinRTContainer container;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()

Check warning on line 28 in samples/features/Features.WinUI3/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'container' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 28 in samples/features/Features.WinUI3/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'container' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
this.InitializeComponent();
}

protected override void Configure()
{
container = new WinRTContainer();
container.RegisterWinRTServices();

container
.PerRequest<MenuViewModel>()
.PerRequest<BindingsViewModel>()
.PerRequest<ActionsViewModel>()
.PerRequest<CoroutineViewModel>()
.PerRequest<ExecuteViewModel>()
.PerRequest<EventAggregationViewModel>()
.PerRequest<DesignTimeViewModel>()
.PerRequest<ConductorViewModel>()
.PerRequest<BubblingViewModel>()
.PerRequest<NavigationSourceViewModel>()
.PerRequest<NavigationTargetViewModel>();
}

protected override void PrepareViewFirst(Frame rootFrame)
{
var navigationService = container.RegisterNavigationService(rootFrame);
}

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
if (args.UWPLaunchActivatedEventArgs.PreviousExecutionState == ApplicationExecutionState.Running)
return;

//DisplayRootView<MenuView>();
DisplayRootNavigationView();
}

protected override object GetInstance(Type service, string key)
{
return container.GetInstance(service, key);
}

protected override IEnumerable<object> GetAllInstances(Type service)
{
return container.GetAllInstances(service);
}

protected override void BuildUp(object instance)
{
container.BuildUp(instance);
}

protected override async void OnUnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
e.Handled = true;

var dialog = new MessageDialog(e.Message, "An error has occurred");

await dialog.ShowAsync();
}

public void GoBack()
{
RootFrame.GoBack();
}

public void DisplayRootNavigationView()
{
Initialize();

InitializeWindow();
PrepareViewFirst();


RootFrame.Navigate(typeof(MenuView), null);

var root = new RootView(RootFrame);

// Seems stupid but observed weird behaviour when resetting the Content
Window.Content = root;

Window.Activate();
}

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions samples/features/Features.WinUI3/Features.WinUI3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Features.WinUI3</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<DefineConstants>WinUI3</DefineConstants>
<EnableMsixTooling>true</EnableMsixTooling>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>

<ItemGroup>
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
</ItemGroup>
<ItemGroup>
<Reference Include="Caliburn.Micro.Core">
<HintPath>..\..\..\bin\Caliburn.Micro.WinUI3\release\net8.0-windows10.0.19041.0\Caliburn.Micro.Core.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform.Core">
<HintPath>..\..\..\bin\Caliburn.Micro.WinUI3\release\net8.0-windows10.0.19041.0\Caliburn.Micro.Platform.Core.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.WinUI3">
<HintPath>..\..\..\bin\Caliburn.Micro.WinUI3\release\net8.0-windows10.0.19041.0\Caliburn.Micro.WinUI3.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="..\Features.CrossPlatform.Shared\Features.CrossPlatform.Shared.projitems" Label="Shared" />

<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>

<!-- Publish Properties -->
<PropertyGroup>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
</PropertyGroup>
</Project>
15 changes: 15 additions & 0 deletions samples/features/Features.WinUI3/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Features.WinUI3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Features.WinUI3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Features.WinUI3">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</Window>
36 changes: 36 additions & 0 deletions samples/features/Features.WinUI3/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Features.WinUI3
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}

private void myButton_Click(object sender, RoutedEventArgs e)
{
myButton.Content = "Clicked";
}
}
}
Loading

0 comments on commit d644b15

Please sign in to comment.