Add another example app

This commit is contained in:
Daniel Clark
2022-11-03 12:33:23 +00:00
parent 854d393b43
commit c601957dd9
38 changed files with 1070 additions and 30 deletions
+454
View File
@@ -0,0 +1,454 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# JetBrains Rider
.idea/
*.sln.iml
##
## Visual Studio Code
##
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
+9
View File
@@ -0,0 +1,9 @@
<Application
x:Class="KingPing.App"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Styles>
<XamlControlsResources />
<StyleInclude Source="avares://TheXamlGuy.UI.Avalonia/Themes/ControlResources.axaml" />
</Application.Styles>
</Application>
+52
View File
@@ -0,0 +1,52 @@
using Avalonia;
using Avalonia.Controls.Shapes;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using PropertyChanged;
using System;
using System.IO;
using TheXamlGuy.Framework.Avalonia;
using TheXamlGuy.Framework.Core;
using Path = System.IO.Path;
namespace KingPing;
[DoNotNotify]
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override async void OnFrameworkInitializationCompleted()
{
IHost? host = new HostBuilder()
.UseContentRoot(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Builder"), true)
.ConfigureTemplates(configuration =>
{
configuration.Add<MainWindowViewModel, MainWindow>();
configuration.Add<MainViewModel, MainView>("Main");
configuration.Add<ShellViewModel, ShellView>("Shell");
configuration.Add<DigitalOutputCollectionViewModel, DigitalOutputCollectionView>("DigitalOutputs");
configuration.Add<DigitalInputCollectionViewModel, DigitalInputCollectionView>("DigitalInputs");
configuration.Add<AnalogOutputCollectionViewModel, AnalogOutputCollectionView>("AnalogOutputs");
configuration.Add<AnalogOutputViewModel, AnalogOutputView>();
configuration.Add<FavouriteCollectionViewModel, FavouriteCollectionView>("Favourites");
})
.ConfigureServices(ConfigureServices)
.Build();
await host.RunAsync();
base.OnFrameworkInitializationCompleted();
}
private void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
services.AddReqiredCore()
.AddRequiredAvalonia()
.AddHostedService<AppServices>()
.RegisterHandlers();
}
}
+3
View File
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
+36
View File
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<TrimmableAssembly Include="Avalonia.Themes.Fluent" />
<TrimmableAssembly Include="Avalonia.Themes.Default" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-preview3" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview3" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0-rc.2.22472.3" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
<PackageReference Include="PropertyChanged.Fody" Version="4.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Framework\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\..\Framework\Core\Core.csproj" />
<ProjectReference Include="..\..\UI\Avalonia.Controls\Avalonia.Controls.csproj" />
<ProjectReference Include="..\..\UI\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\..\UI\UI\UI.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\ShellView.axaml.cs">
<DependentUpon>ShellView.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
+27
View File
@@ -0,0 +1,27 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class StartedHandler : IMediatorHandler<Started>
{
private readonly MainWindow window;
private readonly MainWindowViewModel viewModel;
public StartedHandler(MainWindow window,
MainWindowViewModel viewModel)
{
this.window = window;
this.viewModel = viewModel;
}
public void Handle(Started request)
{
window.DataContext = viewModel;
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = window;
}
}
}
+17
View File
@@ -0,0 +1,17 @@
using Avalonia;
using System;
namespace KingPing
{
internal class Program
{
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}
@@ -0,0 +1,17 @@
<UserControl
x:Class="KingPing.AnalogOutputCollectionView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ScrollViewer Padding="12">
<ItemsRepeater ItemTemplate="{Binding TemplateSelector}" Items="{Binding}">
<ItemsRepeater.Layout>
<UniformGridLayout
ItemsStretch="Uniform"
MinColumnSpacing="12"
MinItemWidth="200"
MinRowSpacing="12"
Orientation="Horizontal" />
</ItemsRepeater.Layout>
</ItemsRepeater>
</ScrollViewer>
</UserControl>
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using PropertyChanged;
namespace KingPing;
[DoNotNotify]
public partial class AnalogOutputCollectionView : UserControl
{
public AnalogOutputCollectionView()
{
InitializeComponent();
}
}
@@ -0,0 +1,22 @@
using System;
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class AnalogOutputCollectionViewModel : ObservableViewModelCollection<AnalogOutputViewModel>
{
public AnalogOutputCollectionViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer,
ITemplateSelector templateSelector) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
for(int i = 0; i < 1000; i++)
{
Add<AnalogOutputViewModel>(Guid.NewGuid().ToString());
}
TemplateSelector = templateSelector;
}
public ITemplateSelector TemplateSelector { get; }
}
@@ -0,0 +1,9 @@
<SettingsExpander
x:Class="KingPing.AnalogOutputView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SettingsExpander.Footer>
<ProgressRing />
</SettingsExpander.Footer>
</SettingsExpander>
@@ -0,0 +1,17 @@
using Avalonia.Styling;
using PropertyChanged;
using System;
using TheXamlGuy.UI.Avalonia.Controls;
namespace KingPing;
[DoNotNotify]
public partial class AnalogOutputView : SettingsExpander, IStyleable
{
public AnalogOutputView()
{
InitializeComponent();
}
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.SettingsExpander);
}
@@ -0,0 +1,17 @@
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class AnalogOutputViewModel : ObservableViewModel
{
public AnalogOutputViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer,
string name) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
Name = name;
}
public string Name { get; }
}
@@ -0,0 +1,6 @@
<UserControl
x:Class="KingPing.DigitalInputCollectionView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
Digital Inputs
</UserControl>
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using PropertyChanged;
namespace KingPing;
[DoNotNotify]
public partial class DigitalInputCollectionView : UserControl
{
public DigitalInputCollectionView()
{
InitializeComponent();
}
}
@@ -0,0 +1,14 @@
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class DigitalInputCollectionViewModel : ObservableViewModel
{
public DigitalInputCollectionViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
}
}
@@ -0,0 +1,6 @@
<UserControl
x:Class="KingPing.DigitalOutputCollectionView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
Digital Outputs
</UserControl>
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using PropertyChanged;
namespace KingPing;
[DoNotNotify]
public partial class DigitalOutputCollectionView : UserControl
{
public DigitalOutputCollectionView()
{
InitializeComponent();
}
}
@@ -0,0 +1,14 @@
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class DigitalOutputCollectionViewModel : ObservableViewModel
{
public DigitalOutputCollectionViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
}
}
@@ -0,0 +1,6 @@
<UserControl
x:Class="KingPing.FavouriteCollectionView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
Favourites
</UserControl>
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using PropertyChanged;
namespace KingPing;
[DoNotNotify]
public partial class FavouriteCollectionView : UserControl
{
public FavouriteCollectionView()
{
InitializeComponent();
}
}
@@ -0,0 +1,14 @@
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class FavouriteCollectionViewModel : ObservableViewModel
{
public FavouriteCollectionViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
}
}
+9
View File
@@ -0,0 +1,9 @@
<UserControl
x:Class="KingPing.MainView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Content="{Route {Binding Route},
Main}"
Loaded="{Navigate {Binding EventAggregator},
Shell,
Route=Main}" />
+13
View File
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using PropertyChanged;
namespace KingPing;
[DoNotNotify]
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
}
}
+18
View File
@@ -0,0 +1,18 @@
using TheXamlGuy.Framework.Avalonia;
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class MainViewModel : ObservableViewModel
{
public MainViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer,
IRouter route) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
Route = route;
}
public IRouter Route { get; }
}
+9
View File
@@ -0,0 +1,9 @@
<Window
x:Class="KingPing.MainWindow"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Content="{Route {Binding Route},
Window}"
Loaded="{Navigate {Binding EventAggregator},
Main,
Route=Window}" />
+13
View File
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using PropertyChanged;
namespace KingPing;
[DoNotNotify]
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
+18
View File
@@ -0,0 +1,18 @@
using TheXamlGuy.Framework.Avalonia;
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class MainWindowViewModel : ObservableViewModel
{
public MainWindowViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer,
IRouter route) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
Route = route;
}
public IRouter Route { get; }
}
+15
View File
@@ -0,0 +1,15 @@
<NavigationView
x:Class="KingPing.ShellView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="NavigationView"
PaneDisplayMode="Top"
SelectionChanged="{Navigate {Binding EventAggregator} {Binding #NavigationView.SelectedItem.Tag}, Route=Frame}">
<NavigationView.MenuItems>
<NavigationViewItem Content="Digital Outputs" Tag="DigitalOutputs" />
<NavigationViewItem Content="Digital Inputs" Tag="DigitalInputs" />
<NavigationViewItem Content="Analog Outputs" Tag="AnalogOutputs" />
<NavigationViewItem Content="Favourites" Tag="Favourites" />
</NavigationView.MenuItems>
<Frame Content="{Route {Binding Route}, Frame}" />
</NavigationView>
+13
View File
@@ -0,0 +1,13 @@
using PropertyChanged;
using TheXamlGuy.UI.Avalonia.Controls;
namespace KingPing;
[DoNotNotify]
public partial class ShellView : NavigationView
{
public ShellView()
{
InitializeComponent();
}
}
+18
View File
@@ -0,0 +1,18 @@
using TheXamlGuy.Framework.Avalonia;
using TheXamlGuy.Framework.Core;
namespace KingPing;
public class ShellViewModel : ObservableViewModel
{
public ShellViewModel(IPropertyBuilder propertyBuilder,
IEventAggregator eventAggregator,
IServiceFactory serviceFactory,
IDisposer disposer,
IRouter route) : base(propertyBuilder, eventAggregator, serviceFactory, disposer)
{
Route = route;
}
public IRouter Route { get; }
}
@@ -7,41 +7,37 @@ using TheXamlGuy.UI.Avalonia.Controls;
namespace TheXamlGuy.Framework.Avalonia; namespace TheXamlGuy.Framework.Avalonia;
public class TemplateSelector : DataTemplateSelector, ITemplateSelector public class TemplateSelector : IDataTemplate, ITemplateSelector
{ {
private readonly Dictionary<object, DataTemplate> dataTracking = new(); private readonly Dictionary<object, IControl> dataTracking = new();
private readonly ITemplateFactory templateFactory;
private readonly IEventAggregator eventAggregator; private readonly IEventAggregator eventAggregator;
private readonly ITemplateFactory templateFactory;
public TemplateSelector(ITemplateFactory templateFactory, public TemplateSelector(ITemplateFactory templateFactory,
IEventAggregator eventAggregator) IEventAggregator eventAggregator)
{ {
this.templateFactory = templateFactory; this.templateFactory = templateFactory;
this.eventAggregator = eventAggregator; this.eventAggregator = eventAggregator;
} }
protected override IDataTemplate SelectTemplateCore(object item, IControl container) public IControl? Build(object? item)
{ {
if (item is not null) if (item is not null)
{ {
if (dataTracking.TryGetValue(item, out DataTemplate? cachedDataTemplate)) if (dataTracking.TryGetValue(item, out IControl? control))
{ {
return cachedDataTemplate; return control;
} }
return new FuncDataTemplate(item.GetType(), (value, namescope) => return (IControl?)templateFactory.Create(item);
{
if (templateFactory.Create(item) is TemplatedControl template)
{
return template;
}
return null;
});
} }
return base.SelectTemplateCore(item, container); return null;
}
public bool Match(object? data)
{
return true;
} }
} }
+12 -1
View File
@@ -37,7 +37,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia", "UI\Avalonia\Ava
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UI", "UI\UI\UI.csproj", "{3094D318-5B54-4367-8195-D47FB431FCB2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UI", "UI\UI\UI.csproj", "{3094D318-5B54-4367-8195-D47FB431FCB2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Controls", "UI\Avalonia.Controls\Avalonia.Controls.csproj", "{DD446126-ABF5-452B-AE93-89A6E6EEF5E5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Controls", "UI\Avalonia.Controls\Avalonia.Controls.csproj", "{DD446126-ABF5-452B-AE93-89A6E6EEF5E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KingPing", "App\KingPing\KingPing.csproj", "{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -159,6 +161,14 @@ Global
{DD446126-ABF5-452B-AE93-89A6E6EEF5E5}.Release|Any CPU.Build.0 = Release|Any CPU {DD446126-ABF5-452B-AE93-89A6E6EEF5E5}.Release|Any CPU.Build.0 = Release|Any CPU
{DD446126-ABF5-452B-AE93-89A6E6EEF5E5}.Release|x64.ActiveCfg = Release|Any CPU {DD446126-ABF5-452B-AE93-89A6E6EEF5E5}.Release|x64.ActiveCfg = Release|Any CPU
{DD446126-ABF5-452B-AE93-89A6E6EEF5E5}.Release|x64.Build.0 = Release|Any CPU {DD446126-ABF5-452B-AE93-89A6E6EEF5E5}.Release|x64.Build.0 = Release|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Debug|x64.ActiveCfg = Debug|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Debug|x64.Build.0 = Debug|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Release|Any CPU.Build.0 = Release|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Release|x64.ActiveCfg = Release|Any CPU
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -178,6 +188,7 @@ Global
{E81C81B3-3FF3-4E1C-B348-C7997D892020} = {793B9D90-DE72-4226-84E8-93FD63548874} {E81C81B3-3FF3-4E1C-B348-C7997D892020} = {793B9D90-DE72-4226-84E8-93FD63548874}
{3094D318-5B54-4367-8195-D47FB431FCB2} = {793B9D90-DE72-4226-84E8-93FD63548874} {3094D318-5B54-4367-8195-D47FB431FCB2} = {793B9D90-DE72-4226-84E8-93FD63548874}
{DD446126-ABF5-452B-AE93-89A6E6EEF5E5} = {793B9D90-DE72-4226-84E8-93FD63548874} {DD446126-ABF5-452B-AE93-89A6E6EEF5E5} = {793B9D90-DE72-4226-84E8-93FD63548874}
{8AE9C2EB-C36D-4122-BE61-A5EEC8BBE8E7} = {10A06ACB-8070-4108-9BF9-AD48D546B56D}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3B239B2D-8C12-47AC-BA53-BB2A3E5BFDB6} SolutionGuid = {3B239B2D-8C12-47AC-BA53-BB2A3E5BFDB6}
@@ -1,6 +0,0 @@
namespace TheXamlGuy.UI.Avalonia.Controls
{
public class DataTemplateSelector : FluentAvalonia.UI.Controls.DataTemplateSelector
{
}
}
@@ -0,0 +1,66 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:TheXamlGuy.UI.Avalonia.Controls;assembly=TheXamlGuy.UI.Avalonia.Controls">
<Design.PreviewWith>
<Border Padding="20">
<ProgressRing />
</Border>
</Design.PreviewWith>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<StaticResource x:Key="ProgressRingForeground" ResourceKey="AccentFillColorDefaultBrush" />
<StaticResource x:Key="ProgressRingBackground" ResourceKey="SubtleFillColorSecondaryBrush" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<x:Double x:Key="ProgressRingStrokeThickness">4</x:Double>
<ControlTheme x:Key="{x:Type controls:ProgressRing}" TargetType="controls:ProgressRing">
<Setter Property="MinWidth" Value="16" />
<Setter Property="MinHeight" Value="16" />
<Setter Property="Height" Value="32" />
<Setter Property="Width" Value="32" />
<Setter Property="Template">
<ControlTemplate>
<Grid>
<Arc
StartAngle="0"
Stroke="{DynamicResource ProgressRingBackground}"
StrokeThickness="{DynamicResource ProgressRingStrokeThickness}"
SweepAngle="360" />
<Arc
x:Name="Arc"
StartAngle="0"
Stroke="{DynamicResource ProgressRingForeground}"
StrokeLineCap="Round"
StrokeThickness="{DynamicResource ProgressRingStrokeThickness}" />
</Grid>
</ControlTemplate>
</Setter>
<Style Selector="^:indeterminate">
<Style Selector="^ /template/ Arc#Arc">
<Setter Property="StartAngle" Value="0" />
<Setter Property="SweepAngle" Value="90" />
<Style.Animations>
<Animation
Easing="SplineEasing"
FillMode="Both"
IterationCount="Infinite"
Duration="0:0:.75">
<KeyFrame Cue="0%">
<Setter Property="StartAngle" Value="0" />
<Setter Property="SweepAngle" Value="180" />
</KeyFrame>
<KeyFrame Cue="50%">
<Setter Property="StartAngle" Value="270" />
<Setter Property="SweepAngle" Value="22.5" />
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="StartAngle" Value="360" />
<Setter Property="SweepAngle" Value="180" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>
@@ -0,0 +1,37 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
namespace TheXamlGuy.UI.Avalonia.Controls
{
public class ProgressRing : RangeBase
{
public static readonly StyledProperty<bool> IsIndeterminateProperty =
AvaloniaProperty.Register<ProgressRing, bool>(nameof(IsIndeterminate), true);
public bool IsIndeterminate
{
get => GetValue(IsIndeterminateProperty);
set => SetValue(IsIndeterminateProperty, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs args)
{
UpdateIsIndeterminate();
}
private void UpdateIsIndeterminate()
{
PseudoClasses.Set(":indeterminate", IsIndeterminate);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == IsIndeterminateProperty)
{
UpdateIsIndeterminate();
}
}
}
}
@@ -0,0 +1,9 @@
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Styles.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://TheXamlGuy.UI.Avalonia.Controls/ProgressRing/ProgressRing.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>
</Styles>
+14 -5
View File
@@ -1,14 +1,23 @@
using FluentAvalonia.Styling; using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using FluentAvalonia.Styling;
using FluentAvalonia.UI.Controls.Primitives;
namespace TheXamlGuy.UI.Avalonia; namespace TheXamlGuy.UI.Avalonia;
public class XamlControlsResources : FluentAvaloniaTheme public class XamlControlsResources : FluentAvaloniaTheme
{ {
public XamlControlsResources(Uri baseUri) : base(baseUri)
{
}
public XamlControlsResources(IServiceProvider serviceProvider) : base(serviceProvider) public XamlControlsResources(IServiceProvider serviceProvider) : base(serviceProvider)
{ {
} }
//private void XamlControlsResources_OwnerChanged(object? sender, EventArgs e)
//{
// Styles styles = (Styles)AvaloniaXamlLoader.Load(new Uri($"avares://TheXamlGuy.UI.Avalonia/Themes/ControlResources.axaml"));
// foreach (var style in styles)
// {
// style.add
// }
//}
} }