Skip to content

Commit

Permalink
Merge pull request #2 from RolandKoenig/1-migrate-to-avalonia-11
Browse files Browse the repository at this point in the history
1 migrate to avalonia 11
  • Loading branch information
RolandKoenig authored Dec 1, 2023
2 parents 290ea9c + f3854fd commit 15a8500
Show file tree
Hide file tree
Showing 50 changed files with 167 additions and 699 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
Expand Down
47 changes: 5 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ DependencyInjection and some Mvvm sugar


## Nuget
| Package | Link |
|-------------------------------------------------|--------------------------------------------------------------------------------|
| RolandK.AvaloniaExtensions | https://www.nuget.org/packages/RolandK.AvaloniaExtensions |
| RolandK.AvaloniaExtensions.FluentThemeDetection | https://www.nuget.org/packages/RolandK.AvaloniaExtensions.FluentThemeDetection |
| RolandK.AvaloniaExtensions.DependencyInjection | https://www.nuget.org/packages/RolandK.AvaloniaExtensions.DependencyInjection |
| Package | Link |
|-------------------------------------------------|-------------------------------------------------------------------------------|
| RolandK.AvaloniaExtensions | https://www.nuget.org/packages/RolandK.AvaloniaExtensions |
| RolandK.AvaloniaExtensions.FluentThemeDetection | (obsolete due to Avalonia 11) |
| RolandK.AvaloniaExtensions.DependencyInjection | https://www.nuget.org/packages/RolandK.AvaloniaExtensions.DependencyInjection |

## Feature overview
- [ViewServices over the popular Mvvm pattern by **not** providing an own Mvvm implementation](#viewservices-over-the-popular-mvvm-pattern)
- [Some default ViewServices (FileDialogs, MessageBox)](#some-default-viewservices)
- [Notification on ViewModels when view is attaching and detaching](#notification-on-viewmodels-when-view-is-attaching-and-detaching)
- [DependencyInjection for Avalonia based on Microsft.Extensions.DependencyInjection](#dependencyinjection-for-avalonia-based-on-microsftextensionsdependencyinjection)
- [Automatically set FluentThemeMode at startup to OS theme (on Windows)](#automatically-set-fluentthememode-at-startup-to-os-theme-on-windows)

# Samples
Here you find samples to the features of RolandK.AvaloniaExtensions. Most of
Expand Down Expand Up @@ -254,40 +253,4 @@ in xaml namespace 'https://github.com/RolandK.AvaloniaExtensions'
d:DataContext="{x:Static local:MainWindowViewModel.DesignViewModel}">
<!-- ... -->
</Window>
```

## Automatically set FluentThemeMode at startup to OS theme (on Windows)
Add nuget package [RolandK.AvaloniaExtensions.FluentThemeDetection](https://www.nuget.org/packages/RolandK.AvaloniaExtensions.FluentThemeDetection).

Ensure that you use a FluentTheme in App.axaml.
```xml
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="RolandK.AvaloniaExtensions.TestApp.App">
<Application.Styles>
<FluentTheme Mode="Dark"/>
</Application.Styles>
</Application>
```

Now you can call UseFluentThemeDetection from within your Program.cs.
This method will automatically search for FluentTheme in the Application's styles
and updates the Mode property.
```csharp
using RolandK.AvaloniaExtensions.FluentThemeDetection;

public static class Program
{
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
//...
.UseFluentThemeDetection();
}
```

You can also call the extension method TrySetFluentThemeMode on your Application object
to set the currently active theme manually. This method doesn't need a call to UseFluentThemeDetection
during startup.
```csharp
Application.Current.TrySetFluentThemeMode(FluentThemeMode.Light);
```
28 changes: 11 additions & 17 deletions RolandK.AvaloniaExtensions.sln
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions.TestApp", "src\RolandK.AvaloniaExtensions.TestApp\RolandK.AvaloniaExtensions.TestApp.csproj", "{AF09D6F7-A9B7-4FBD-A1B2-ACE25418E813}"
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolandK.AvaloniaExtensions.TestApp", "src\RolandK.AvaloniaExtensions.TestApp\RolandK.AvaloniaExtensions.TestApp.csproj", "{AF09D6F7-A9B7-4FBD-A1B2-ACE25418E813}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions", "src\RolandK.AvaloniaExtensions\RolandK.AvaloniaExtensions.csproj", "{779B4BE6-6030-4B49-87D4-9162F9E50FCA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolandK.AvaloniaExtensions", "src\RolandK.AvaloniaExtensions\RolandK.AvaloniaExtensions.csproj", "{779B4BE6-6030-4B49-87D4-9162F9E50FCA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions.DependencyInjection", "src\RolandK.AvaloniaExtensions.DependencyInjection\RolandK.AvaloniaExtensions.DependencyInjection.csproj", "{4D4CA940-68F9-4EE2-9030-921C0A1B163E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolandK.AvaloniaExtensions.DependencyInjection", "src\RolandK.AvaloniaExtensions.DependencyInjection\RolandK.AvaloniaExtensions.DependencyInjection.csproj", "{4D4CA940-68F9-4EE2-9030-921C0A1B163E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions.Tests", "src\RolandK.AvaloniaExtensions.Tests\RolandK.AvaloniaExtensions.Tests.csproj", "{270741C0-1A15-4C44-8A1C-0DD86DD8DF23}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolandK.AvaloniaExtensions.Tests", "src\RolandK.AvaloniaExtensions.Tests\RolandK.AvaloniaExtensions.Tests.csproj", "{270741C0-1A15-4C44-8A1C-0DD86DD8DF23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions.FluentThemeDetection", "src\RolandK.AvaloniaExtensions.FluentThemeDetection\RolandK.AvaloniaExtensions.FluentThemeDetection.csproj", "{F78873DB-5864-4C50-93A2-C6371D0D26EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions.DependencyInjection.Tests", "src\RolandK.AvaloniaExtensions.DependencyInjection.Tests\RolandK.AvaloniaExtensions.DependencyInjection.Tests.csproj", "{03D69FBA-0153-4CF3-AC81-07E8CC0BB526}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RolandK.AvaloniaExtensions.FluentThemeDetection.Tests", "src\RolandK.AvaloniaExtensions.FluentThemeDetection.Tests\RolandK.AvaloniaExtensions.FluentThemeDetection.Tests.csproj", "{22806B2B-89D8-4B3F-886E-2B54D734E9BD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RolandK.AvaloniaExtensions.DependencyInjection.Tests", "src\RolandK.AvaloniaExtensions.DependencyInjection.Tests\RolandK.AvaloniaExtensions.DependencyInjection.Tests.csproj", "{03D69FBA-0153-4CF3-AC81-07E8CC0BB526}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -36,17 +35,12 @@ Global
{270741C0-1A15-4C44-8A1C-0DD86DD8DF23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{270741C0-1A15-4C44-8A1C-0DD86DD8DF23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{270741C0-1A15-4C44-8A1C-0DD86DD8DF23}.Release|Any CPU.Build.0 = Release|Any CPU
{F78873DB-5864-4C50-93A2-C6371D0D26EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F78873DB-5864-4C50-93A2-C6371D0D26EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F78873DB-5864-4C50-93A2-C6371D0D26EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F78873DB-5864-4C50-93A2-C6371D0D26EF}.Release|Any CPU.Build.0 = Release|Any CPU
{03D69FBA-0153-4CF3-AC81-07E8CC0BB526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03D69FBA-0153-4CF3-AC81-07E8CC0BB526}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03D69FBA-0153-4CF3-AC81-07E8CC0BB526}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03D69FBA-0153-4CF3-AC81-07E8CC0BB526}.Release|Any CPU.Build.0 = Release|Any CPU
{22806B2B-89D8-4B3F-886E-2B54D734E9BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{22806B2B-89D8-4B3F-886E-2B54D734E9BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{22806B2B-89D8-4B3F-886E-2B54D734E9BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{22806B2B-89D8-4B3F-886E-2B54D734E9BD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<!-- Version -->
<PropertyGroup>
<Version>1.0.1</Version>
<PackageVersion>1.0.1</PackageVersion>
<Version>2.0.0</Version>
<PackageVersion>1.0.0</PackageVersion>
</PropertyGroup>

<!-- Nuget -->
Expand Down Expand Up @@ -42,7 +42,7 @@
<!-- Commn configuration-->
<PropertyGroup>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
<LangVersion>11.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<NoWarn>1591,1712</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -19,7 +19,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="Avalonia.Headless" Version="0.10.21" />
<PackageReference Include="Avalonia.Headless" Version="11.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace RolandK.AvaloniaExtensions.DependencyInjection.Tests.Util;
internal class TestRootWindow : Window
{
public TestRootWindow()
: base(Substitute.For<IWindowImpl>())
: base()
{

}

public TestRootWindow(IControl initialChild)
public TestRootWindow(Control initialChild)
: this()
{
this.Content = initialChild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static async Task RunInApplicationContextAsync(Action? action = null)
{
AppBuilder.Configure<UnitTestApplication>()
.LogToTrace()
.UseHeadless()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.UseDependencyInjection(DependencyInjectionTests.AddServicesForUnitTests)
.AfterSetup(_ => taskComplSource.SetResult())
.StartWithClassicDesktopLifetime(Array.Empty<string>(), ShutdownMode.OnExplicitShutdown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static AppBuilder UseDependencyInjection(this AppBuilder appBuilder, Acti

appBuilder.AfterSetup(x =>
{
if (x == null) { return; }
if (x.Instance == null) { return; }

var services = new ServiceCollection();

registerServicesAction(services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ public CreateUsingDependencyInjectionExtension(Type type)
}

/// <inheritdoc />
public override object? ProvideValue(IServiceProvider serviceProvider)
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (this.Type == null) { return null; }
if (Design.IsDesignMode) { return null; }
if (this.Type == null) { return null!; }
if (Design.IsDesignMode) { return null!; }

var rootObjProvider = serviceProvider.GetService<IRootObjectProvider>();

if (rootObjProvider?.RootObject is not IControl rootObj) { return null; }
if (rootObjProvider?.RootObject is not Control rootObj) { return null!; }

var appServiceProvider =
rootObj.FindResource(DependencyInjectionConstants.SERVICE_PROVIDER_RESOURCE_KEY) as IServiceProvider;
if (appServiceProvider == null)
{
var targetPropertyAccessor = serviceProvider.GetService<IProvideValueTarget>();
if (targetPropertyAccessor == null) { return null; }
if (targetPropertyAccessor == null) { return null!; }

var targetProperty = targetPropertyAccessor.TargetProperty as AvaloniaProperty;
var targetControl = targetPropertyAccessor.TargetObject as IControl;
var targetControl = targetPropertyAccessor.TargetObject as Control;
if ((targetControl == null) ||
(targetProperty == null))
{
return null;
return null!;
}

EventHandler<LogicalTreeAttachmentEventArgs>? eventHandler = null;
Expand All @@ -65,6 +65,6 @@ public CreateUsingDependencyInjectionExtension(Type type)
return appServiceProvider.GetRequiredService(this.Type);
}

return null;
return null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.21" />
<PackageReference Include="Avalonia" Version="11.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 15a8500

Please sign in to comment.