This commit is contained in:
bunny 2024-10-21 10:12:01 +08:00
commit 9dc2edbba2
22 changed files with 533 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/projectSettingsUpdater.xml
/.idea.AvaloniaApplication1.iml
/contentModel.xml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AvaloniaProject">
<option name="projectPerEditor">
<map>
<entry key="AvaloniaApplication1/App.axaml" value="AvaloniaApplication1/AvaloniaApplication1.csproj" />
<entry key="AvaloniaApplication1/Views/LayoutWindow.axaml" value="AvaloniaApplication1/AvaloniaApplication1.csproj" />
<entry key="AvaloniaApplication1/Views/MainWindow.axaml" value="AvaloniaApplication1/AvaloniaApplication1.csproj" />
</map>
</option>
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

16
AvaloniaApplication1.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaApplication1", "AvaloniaApplication1\AvaloniaApplication1.csproj", "{7C01A027-9871-48D5-A415-84AB4192017B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7C01A027-9871-48D5-A415-84AB4192017B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C01A027-9871-48D5-A415-84AB4192017B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C01A027-9871-48D5-A415-84AB4192017B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C01A027-9871-48D5-A415-84AB4192017B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**

23
AvaloniaApplication1/.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
# Build and Release Folders
bin-debug/
bin-release/
[Oo]bj/
[Bb]in/
# Other files and folders
.settings/
# Executables
*.swf
*.air
*.ipa
*.apk
*.log
.vs
# .idea
.DS_Store
**/bin
**/obj

View File

@ -0,0 +1,40 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaApplication1.App"
xmlns:local="using:AvaloniaApplication1"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>
<Application.Styles>
<FluentTheme>
<FluentTheme>
<FluentTheme.Palettes>
<ColorPaletteResources x:Key="Light" Accent="#ff8961cc" AltHigh="White" AltLow="White"
AltMedium="White" AltMediumHigh="White" AltMediumLow="White"
BaseHigh="Black" BaseLow="#ffeeceff" BaseMedium="#ffa987bc"
BaseMediumHigh="#ff7b5890" BaseMediumLow="#ff9270a6"
ChromeAltLow="#ff7b5890" ChromeBlackHigh="Black" ChromeBlackLow="#ffeeceff"
ChromeBlackMedium="#ff7b5890" ChromeBlackMediumLow="#ffa987bc"
ChromeDisabledHigh="#ffeeceff" ChromeDisabledLow="#ffa987bc"
ChromeGray="#ff9270a6" ChromeHigh="#ffeeceff" ChromeLow="#fffeeaff"
ChromeMedium="#fffbe4ff" ChromeMediumLow="#fffeeaff" ChromeWhite="White"
ListLow="#fffbe4ff" ListMedium="#ffeeceff" RegionColor="#fffef6ff" />
<ColorPaletteResources x:Key="Dark" Accent="#ff8961cc" AltHigh="Black" AltLow="Black"
AltMedium="Black" AltMediumHigh="Black" AltMediumLow="Black"
BaseHigh="White" BaseLow="#ff64576b" BaseMedium="#ffb6aabc"
BaseMediumHigh="#ffcbbfd0" BaseMediumLow="#ff8d8193"
ChromeAltLow="#ffcbbfd0" ChromeBlackHigh="Black" ChromeBlackLow="#ffcbbfd0"
ChromeBlackMedium="Black" ChromeBlackMediumLow="Black"
ChromeDisabledHigh="#ff64576b" ChromeDisabledLow="#ffb6aabc"
ChromeGray="#ffa295a8" ChromeHigh="#ffa295a8" ChromeLow="#ff332041"
ChromeMedium="#ff3f2e4b" ChromeMediumLow="#ff584960" ChromeWhite="White"
ListLow="#ff3f2e4b" ListMedium="#ff64576b" RegionColor="#ff262738" />
</FluentTheme.Palettes>
</FluentTheme>
</FluentTheme>
</Application.Styles>
</Application>

View File

@ -0,0 +1,33 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using AvaloniaApplication1.ViewModels;
using AvaloniaApplication1.Views;
namespace AvaloniaApplication1;
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
BindingPlugins.DataValidators.RemoveAt(0);
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\"/>
<AvaloniaResource Include="Assets\**"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.0-rc1"/>
<PackageReference Include="Avalonia.Desktop" Version="11.2.0-rc1"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.0-rc1"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.0-rc1"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.0-rc1"/>
<!--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.0-rc1"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2"/>
<PackageReference Include="MessageBox.Avalonia" Version="3.1.6.13"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
using System;
using Avalonia;
using Avalonia.ReactiveUI;
namespace AvaloniaApplication1;
public static class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
{
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace().UseReactiveUI();
}
}

View File

@ -0,0 +1,28 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using AvaloniaApplication1.ViewModels;
namespace AvaloniaApplication1;
public class ViewLocator : IDataTemplate
{
public Control? Build(object? data)
{
if (data is null)
return null;
var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
var type = Type.GetType(name);
if (type == null) return new TextBlock { Text = "Not Found: " + name };
var control = (Control)Activator.CreateInstance(type)!;
control.DataContext = data;
return control;
}
public bool Match(object? data)
{
return data is ViewModelBase;
}
}

View File

@ -0,0 +1,5 @@
namespace AvaloniaApplication1.ViewModels;
public class LayoutWindowViewModel : ViewModelBase
{
}

View File

@ -0,0 +1,5 @@
namespace AvaloniaApplication1.ViewModels;
public class MainWindowViewModel : ViewModelBase
{
}

View File

@ -0,0 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
namespace AvaloniaApplication1.ViewModels;
public class ViewModelBase : ObservableObject
{
}

View File

@ -0,0 +1,107 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:AvaloniaApplication1.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="1200"
Height="800"
x:Class="AvaloniaApplication1.Views.LayoutWindow"
x:DataType="viewModels:LayoutWindowViewModel"
Title="LayoutWindow"
TransparencyLevelHint="AcrylicBlur"
ExtendClientAreaChromeHints="Default"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaTitleBarHeightHint="-1"
Background="Tan"
WindowStartupLocation="CenterOwner">
<Grid>
<StackPanel Margin="10,10,-10,0" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<StackPanel>
<TextBlock Text="Default Button" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<Button Content="Enabled" />
<Button Content="Disabled" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
<StackPanel Margin="20,0">
<TextBlock Text="Toggle Button" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<ToggleButton Content="Enabled" />
<ToggleButton Content="Checked" IsChecked="True" Margin="0,5,0,0" />
<ToggleButton Content="Disabled" IsEnabled="False" Margin="0,5,0,0" />
<ToggleButton Content="Checked" IsChecked="True" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
<StackPanel>
<TextBlock Text="Toggle Switch" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<ToggleSwitch Content="Enabled" />
<ToggleSwitch Content="Checked" IsChecked="True" Margin="0,5,0,0" />
<ToggleSwitch Content="Disabled" IsEnabled="False" Margin="0,5,0,0" />
<ToggleSwitch Content="Checked" IsChecked="True" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
<StackPanel Margin="20,0">
<TextBlock Text="CheckBox" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<CheckBox Content="Enabled" />
<CheckBox Content="Checked" IsChecked="True" Margin="0,5,0,0" />
<CheckBox Content="3-State" IsChecked="{x:Null}" IsThreeState="True" Margin="0,5,0,0" />
<CheckBox Content="Disabled" IsEnabled="False" Margin="0,5,0,0" />
<CheckBox Content="Checked" IsChecked="True" IsEnabled="False" Margin="0,5,0,0" />
<CheckBox Content="3-State" IsChecked="{x:Null}" IsThreeState="True" IsEnabled="False"
Margin="0,5,0,0" />
</StackPanel>
<StackPanel Margin="20,0">
<TextBlock Text="RadioButton" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<StackPanel>
<RadioButton Content="Enabled" />
<RadioButton Content="Checked" IsChecked="True" Margin="0,5,0,0" />
</StackPanel>
<StackPanel>
<RadioButton Content="Disabled" IsEnabled="False" Margin="0,5,0,0" />
<RadioButton Content="Checked" IsChecked="True" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,20,0,0">
<StackPanel>
<TextBlock Text="TextBox" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<TextBox Text="Enabled" />
<TextBox Watermark="Placeholder" Margin="0,5,0,0" />
<TextBox Text="Disabled" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
<StackPanel Margin="20,0">
<TextBlock Text="PasswordBox" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<TextBox PasswordChar="*" Text="Enabled" />
<TextBox PasswordChar="*" Watermark="Placeholder" Margin="0,5,0,0" />
<TextBox PasswordChar="*" Text="Disabled" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
<StackPanel>
<TextBlock Text="Slider" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<Slider Value="0" MinWidth="120" />
<Slider Value="1" TickPlacement="Outside" Margin="0,5,0,0" />
<Slider Value="2" IsDirectionReversed="True" TickPlacement="BottomRight" Margin="0,5,0,0" />
<Slider Value="5" IsEnabled="False" Margin="0,5,0,0" />
</StackPanel>
<StackPanel Margin="20,0">
<TextBlock Text="ListBox" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<ListBox BorderThickness="1">
<ListBoxItem Content="Unselected" />
<ListBoxItem Content="Selected" />
<ListBoxItem Content="Disabled" IsEnabled="False" />
</ListBox>
</StackPanel>
<StackPanel>
<TextBlock Text="TreeView" FontSize="18" TextAlignment="Center" Margin="0,0,0,10" />
<TreeView BorderThickness="1">
<TreeViewItem Header="Expanded" IsExpanded="True">
<TreeViewItem Header="Child" />
</TreeViewItem>
<TreeViewItem Header="Collapsed">
<TreeViewItem Header="Child" />
</TreeViewItem>
<TreeViewItem Header="Disabled" IsEnabled="False">
<TreeViewItem Header="Child" />
</TreeViewItem>
</TreeView>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,11 @@
using Avalonia.Controls;
namespace AvaloniaApplication1.Views;
public partial class LayoutWindow : Window
{
public LayoutWindow()
{
InitializeComponent();
}
}

View File

@ -0,0 +1,31 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:AvaloniaApplication1.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="1200"
Height="800"
x:Class="AvaloniaApplication1.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="AvaloniaApplication1"
TransparencyLevelHint="AcrylicBlur"
Background="Pink"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaTitleBarHeightHint="-1"
BackgroundSizing="CenterBorder"
WindowStartupLocation="CenterScreen">
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainWindowViewModel />
</Design.DataContext>
<StackPanel>
<Button Content="显示布局" Click="ShowLayoutOnClick" />
<Button Name="MainButton" Click="MainButtOnClick" />
</StackPanel>
</Window>

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using AvaloniaApplication1.ViewModels;
using MsBox.Avalonia;
using MsBox.Avalonia.Dto;
using MsBox.Avalonia.Models;
namespace AvaloniaApplication1.Views;
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
{
public MainWindow()
{
InitializeComponent();
MainButton.Content = "主页的按钮";
MainButton.Background = Brushes.YellowGreen;
}
private async void MainButtOnClick(object? sender, RoutedEventArgs e)
{
var showAsync = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
{
ButtonDefinitions = new List<ButtonDefinition>
{
new() { Name = "是" },
new() { Name = "否" },
new() { Name = "Cancel" }
},
ContentTitle = "title",
ContentMessage = "Informative note:" +
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut pulvinar est, eget porttitor magna. Maecenas nunc elit, pretium nec mauris vel, cursus faucibus leo. Mauris consequat magna vel mi malesuada semper. Donec nunc justo, rhoncus vel viverra a, ultrices vel nibh. Praesent ut libero a nunc placerat vulputate. Morbi ullamcorper pharetra lectus, ut lobortis ex consequat sit amet. Vestibulum pellentesque quam at justo hendrerit, et tincidunt nisl mattis. Curabitur eu nibh enim.\n",
Icon = MsBox.Avalonia.Enums.Icon.Question,
CanResize = false,
MaxWidth = 500,
MaxHeight = 800,
ShowInCenter = true,
Topmost = false,
HyperLinkParams = new HyperLinkParams
{
Text = "https://docs.avaloniaui.net/",
Action = () =>
{
var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var url = "https://docs.avaloniaui.net/";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//https://stackoverflow.com/a/2796367/241446
using var proc = new Process();
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = url;
proc.Start();
return;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("x-www-browser", url);
return;
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
throw new Exception("invalid url: " + url);
Process.Start("open", url);
}
}
}).ShowAsync();
Console.WriteLine(await showAsync);
}
private void ShowLayoutOnClick(object? sender, RoutedEventArgs e)
{
var layoutWindow = new LayoutWindow();
layoutWindow.ShowDialog<string>(this);
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embedded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="AvaloniaApplication1.Desktop"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>