Skip to content

Commit 1918d4e

Browse files
committed
Updated WinUI demo
1 parent d6f80d4 commit 1918d4e

23 files changed

Lines changed: 419 additions & 412 deletions

Demo-WinUI/Demo-WinUI.sln

Lines changed: 0 additions & 43 deletions
This file was deleted.

Demo-WinUI/Demo-WinUI.slnx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Solution>
2+
<Configurations>
3+
<Platform Name="ARM64" />
4+
<Platform Name="x64" />
5+
<Platform Name="x86" />
6+
</Configurations>
7+
<Project Path="Demo-WinUI/Demo-WinUI.csproj">
8+
<Platform Solution="*|ARM64" Project="ARM64" />
9+
<Platform Solution="*|x64" Project="x64" />
10+
<Platform Solution="*|x86" Project="x86" />
11+
<Deploy />
12+
</Project>
13+
</Solution>

Demo-WinUI/Demo-WinUI/App.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<!-- Swiss QR Bill Generator for .NET -->
2-
<!-- Copyright (c) 2022 Manuel Bleichenbacher -->
3+
<!-- Copyright (c) 2026 Manuel Bleichenbacher -->
34
<!-- Licensed under MIT License -->
45
<!-- https://opensource.org/licenses/MIT -->
56

Demo-WinUI/Demo-WinUI/App.xaml.cs

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,38 @@
11
//
22
// Swiss QR Bill Generator for .NET
3-
// Copyright (c) 2022 Manuel Bleichenbacher
3+
// Copyright (c) 2026 Manuel Bleichenbacher
44
// Licensed under MIT License
55
// https://opensource.org/licenses/MIT
66
//
77

8-
using Microsoft.UI;
9-
using Microsoft.UI.Windowing;
108
using Microsoft.UI.Xaml;
11-
using System;
12-
using System.Runtime.InteropServices;
13-
using Windows.Graphics;
14-
using WinRT.Interop;
15-
using Windows.Win32;
16-
using Windows.Win32.Foundation;
179

18-
namespace Net.Codecrete.QrCodeGenerator.Demo;
19-
20-
/// <summary>
21-
/// QR Code application.
22-
/// </summary>
23-
public partial class App : Application
10+
namespace Net.Codecrete.QrCodeGenerator.Demo
2411
{
2512
/// <summary>
26-
/// Initializes the singleton application object. This is the first line of authored code
27-
/// executed, and as such is the logical equivalent of main() or WinMain().
13+
/// QR Code application.
2814
/// </summary>
29-
public App()
15+
public partial class App : Application
3016
{
31-
InitializeComponent();
32-
}
17+
private Window? _window;
3318

34-
/// <summary>
35-
/// Invoked when the application is launched.
36-
/// </summary>
37-
/// <param name="args">Details about the launch request and process.</param>
38-
protected override void OnLaunched(LaunchActivatedEventArgs args)
39-
{
40-
m_window = new MainWindow
19+
/// <summary>
20+
/// Initializes the singleton application object. This is the first line of authored code
21+
/// executed, and as such is the logical equivalent of main() or WinMain().
22+
/// </summary>
23+
public App()
4124
{
42-
Title = "QR Code"
43-
};
44-
45-
// Set initial windows size.
46-
Resize(500, 600);
47-
48-
m_window.Activate();
49-
}
50-
51-
private Window m_window;
52-
53-
private void Resize(int x, int y)
54-
{
55-
var scalingFactor = GetDpiScalingFactor();
56-
GetAppWindow().Resize(new SizeInt32((int)(x * scalingFactor), (int)(y * scalingFactor)));
57-
}
58-
59-
private AppWindow GetAppWindow()
60-
{
61-
IntPtr hWnd = WindowNative.GetWindowHandle(m_window);
62-
WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
63-
return AppWindow.GetFromWindowId(wndId);
64-
}
65-
66-
private double GetDpiScalingFactor()
67-
{
68-
IntPtr hWnd = WindowNative.GetWindowHandle(m_window);
69-
var dpi = PInvoke.GetDpiForWindow((HWND)hWnd);
70-
return (float)dpi / 96;
25+
InitializeComponent();
26+
}
27+
28+
/// <summary>
29+
/// Invoked when the application is launched.
30+
/// </summary>
31+
/// <param name="args">Details about the launch request and process.</param>
32+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
33+
{
34+
_window = new MainWindow();
35+
_window.Activate();
36+
}
7137
}
7238
}
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
55
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
66
<RootNamespace>Net.Codecrete.QrCodeGenerator.Demo</RootNamespace>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<Platforms>x86;x64;ARM64</Platforms>
99
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
1010
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
1111
<UseWinUI>true</UseWinUI>
12+
<WinUISDKReferences>false</WinUISDKReferences>
1213
<EnableMsixTooling>true</EnableMsixTooling>
14+
<Nullable>enable</Nullable>
15+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1316
<AssemblyName>QrCodeWinUIDemo</AssemblyName>
14-
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
15-
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
16-
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
17-
<GenerateTestArtifacts>True</GenerateTestArtifacts>
18-
<AppxBundle>Never</AppxBundle>
19-
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
2017
</PropertyGroup>
2118
<ItemGroup>
22-
<None Remove="QrCodeControl.xaml" />
19+
<None Remove="QrCodePage.xaml" />
20+
<None Remove="Views\QrCodeControl.xaml" />
2321
</ItemGroup>
2422

2523
<ItemGroup>
@@ -33,19 +31,16 @@
3331
</ItemGroup>
3432

3533
<ItemGroup>
36-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
3734
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.4.0" />
38-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.275">
39-
<PrivateAssets>all</PrivateAssets>
40-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
41-
</PackageReference>
4235
<PackageReference Include="Microsoft.WindowsAppSDK" Version="2.0.1" />
4336
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.28000.1839" />
4437
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="3.0.0" />
38+
</ItemGroup>
39+
<ItemGroup>
4540
<Manifest Include="$(ApplicationManifest)" />
4641
</ItemGroup>
4742

48-
<!--
43+
<!--
4944
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
5045
Tools extension to be activated for this project even if the Windows App SDK Nuget
5146
package has not yet been restored.
@@ -54,17 +49,33 @@
5449
<ProjectCapability Include="Msix" />
5550
</ItemGroup>
5651
<ItemGroup>
57-
<Page Update="QrCodeControl.xaml">
52+
<Page Update="Views\QrCodeControl.xaml">
53+
<Generator>MSBuild:Compile</Generator>
54+
</Page>
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Page Update="QrCodePage.xaml">
5858
<Generator>MSBuild:Compile</Generator>
5959
</Page>
6060
</ItemGroup>
61+
<ItemGroup>
62+
<Folder Include="Models\" />
63+
</ItemGroup>
6164

62-
<!--
63-
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
64-
Explorer "Package and Publish" context menu entry to be enabled for this project even if
65+
<!--
66+
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
67+
Explorer "Package and Publish" context menu entry to be enabled for this project even if
6568
the Windows App SDK Nuget package has not yet been restored.
6669
-->
6770
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
6871
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
6972
</PropertyGroup>
73+
74+
<!-- Publish Properties -->
75+
<PropertyGroup>
76+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
77+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
78+
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
79+
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
80+
</PropertyGroup>
7081
</Project>

Demo-WinUI/Demo-WinUI/MainViewModel.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<!-- Swiss QR Bill Generator for .NET -->
2-
<!-- Copyright (c) 2022 Manuel Bleichenbacher -->
3+
<!-- Copyright (c) 2026 Manuel Bleichenbacher -->
34
<!-- Licensed under MIT License -->
45
<!-- https://opensource.org/licenses/MIT -->
56

67
<Window
78
x:Class="Net.Codecrete.QrCodeGenerator.Demo.MainWindow"
89
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
910
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
11+
xmlns:views="using:Net.Codecrete.QrCodeGenerator.Demo.Views"
1012
xmlns:local="using:Net.Codecrete.QrCodeGenerator.Demo"
1113
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
1214
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
13-
mc:Ignorable="d">
15+
mc:Ignorable="d"
16+
Title="Demo-WinUI">
1417

18+
<Window.SystemBackdrop>
19+
<MicaBackdrop Kind="Base" />
20+
</Window.SystemBackdrop>
1521

16-
<Grid x:Name="RootElement" Background="#fff7f7f7">
17-
<Grid Margin="20,16,20,16">
22+
<Grid>
23+
<Grid.RowDefinitions>
24+
<!-- Title Bar -->
25+
<RowDefinition Height="Auto" />
26+
<!-- App Content -->
27+
<RowDefinition Height="*" />
28+
</Grid.RowDefinitions>
29+
<TitleBar x:Name="AppTitleBar" Title="QR Code">
30+
<TitleBar.IconSource>
31+
<FontIconSource Glyph="&#xED14;"/>
32+
</TitleBar.IconSource>
33+
</TitleBar>
1834

19-
<Grid.ColumnDefinitions>
20-
<ColumnDefinition Width="1*"/>
21-
</Grid.ColumnDefinitions>
22-
<Grid.RowDefinitions>
23-
<RowDefinition Height="1*"/>
24-
<RowDefinition Height="Auto"/>
25-
<RowDefinition Height="Auto"/>
26-
<RowDefinition Height="Auto"/>
27-
</Grid.RowDefinitions>
28-
<local:QrCodeControl x:Name="QrCodeControl" Grid.Row="0" Margin="0,0,0,16"
29-
Text="{x:Bind ViewModel.Text, Mode=TwoWay}" ErrorCorrection="{x:Bind ViewModel.ErrorCorrection, Mode=TwoWay}" BorderWidth="{x:Bind ViewModel.BorderWidth, Mode=TwoWay}" />
30-
<TextBox x:Name="QrCodeTextBox" Text="{x:Bind ViewModel.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Padding="5,3" Margin="0,6"/>
31-
<VariableSizedWrapGrid Grid.Row="2" Orientation="Horizontal">
32-
<StackPanel Orientation="Horizontal">
33-
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0,5,12,5">Error Correction:</TextBlock>
34-
<ComboBox x:Name="ErrorCorrectionCombo" HorizontalAlignment="Left" VerticalAlignment="Center" Width="140" Margin="0,6,24,6"
35-
ItemsSource="{x:Bind ViewModel.ErrorCorrectionLevels, Mode=OneTime}" DisplayMemberPath="Item1" SelectedValuePath="Item2" SelectedValue="{x:Bind ViewModel.ErrorCorrection, Mode=TwoWay}" />
36-
</StackPanel>
37-
<StackPanel Orientation="Horizontal">
38-
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0,5,12,5">Border Width:</TextBlock>
39-
<NumberBox x:Name="BorderWidthTextBox" Value="{x:Bind ViewModel.BorderWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
40-
SpinButtonPlacementMode="Inline" Minimum="0" Maximum="999" HorizontalAlignment="Left" VerticalAlignment="Center" Width="150" Margin="0,6" Padding="5,3"/>
41-
</StackPanel>
42-
</VariableSizedWrapGrid>
43-
<Button x:Name="CopyButton" Command="{x:Bind ViewModel.CopyToClipboardCommand}" Content="Copy QR Code" Grid.Row="3" Margin="0,6,0,0"
44-
VerticalAlignment="Center" HorizontalAlignment="Right" Padding="10,3" Grid.ColumnSpan="4" />
45-
</Grid>
35+
<!-- App content -->
36+
<Frame x:Name="rootFrame" Grid.Row="1" SourcePageType="views:QrCodeView"/>
4637
</Grid>
38+
4739
</Window>

0 commit comments

Comments
 (0)