Skip to content

Commit 06933f7

Browse files
init
0 parents  commit 06933f7

14 files changed

+1025
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vs/
2+
Counter/obj/

Counter.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35716.79 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Counter", "Counter\Counter.csproj", "{B7ECF9E1-6808-4F83-BC8E-C6B940D82304}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B7ECF9E1-6808-4F83-BC8E-C6B940D82304}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B7ECF9E1-6808-4F83-BC8E-C6B940D82304}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B7ECF9E1-6808-4F83-BC8E-C6B940D82304}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B7ECF9E1-6808-4F83-BC8E-C6B940D82304}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F8E61A3B-2F33-4426-9C37-0FDA8F0F7639}
24+
EndGlobalSection
25+
EndGlobal

Counter/App.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Themes.Fluent;
4+
using Avalonia.Themes.Simple;
5+
using Classic.Avalonia.Theme;
6+
using Material.Styles.Themes;
7+
8+
namespace Counter;
9+
10+
internal class App : Application
11+
{
12+
public override void Initialize()
13+
{
14+
RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Default;
15+
Styles.Add(new FluentTheme());
16+
}
17+
18+
public override void OnFrameworkInitializationCompleted()
19+
{
20+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
21+
desktop.MainWindow = new MainWindow(new MainViewModel());
22+
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewApplication)
23+
singleViewApplication.MainView = new MainWindow(new MainViewModel());
24+
base.OnFrameworkInitializationCompleted();
25+
}
26+
}

Counter/CommonTransitions.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Avalonia.Animation;
2+
using Avalonia.Animation.Easings;
3+
using Avalonia.Controls;
4+
using Avalonia.Layout;
5+
6+
namespace Counter;
7+
8+
public static class CommonTransitions
9+
{
10+
private static readonly TimeSpan Delay = TimeSpan.FromSeconds(0.1);
11+
private static readonly TimeSpan Durartion = TimeSpan.FromSeconds(0.3);
12+
private static readonly Easing Easing = new SineEaseInOut();
13+
14+
public static readonly DoubleTransition Width = new()
15+
{
16+
Property = Layoutable.WidthProperty,
17+
Delay = Delay,
18+
Duration = Durartion,
19+
Easing = Easing
20+
};
21+
22+
public static readonly DoubleTransition Height = new()
23+
{
24+
Property = Layoutable.HeightProperty,
25+
Delay = Delay,
26+
Duration = Durartion,
27+
Easing = Easing
28+
};
29+
30+
public static readonly CornerRadiusTransition CornerRadius = new()
31+
{
32+
Property = Border.CornerRadiusProperty,
33+
Delay = Delay,
34+
Duration = Durartion,
35+
Easing = Easing
36+
};
37+
38+
public static readonly DoubleTransition Opacity = new()
39+
{
40+
Property = Avalonia.Visual.OpacityProperty,
41+
Delay = Delay,
42+
Duration = Durartion,
43+
Easing = Easing
44+
};
45+
46+
public static readonly Transitions BasicTransitions = [Width, Height, Opacity, CornerRadius];
47+
}

Counter/ControlsExtensions.cs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Controls.Primitives;
3+
using Avalonia.Interactivity;
4+
5+
namespace Counter
6+
{
7+
public static class ControlsExtensions
8+
{
9+
public static Button OnClick(this Button button, params Action<Button, RoutedEventArgs>[] callbacks)
10+
{
11+
for (int i = 0; i < callbacks.Length; i++)
12+
{
13+
int index = 0;
14+
button.Click += (obj, args) => callbacks[index]((Button)obj!, args);
15+
}
16+
17+
return button;
18+
}
19+
20+
public static Button OnClick(this Button button, Action<Button, RoutedEventArgs> callback)
21+
{
22+
button.Click += (obj, args) => callback((Button)obj!, args);
23+
return button;
24+
}
25+
26+
public static Button OnClick(this Button button, params Action[] callbacks)
27+
{
28+
for (int i = 0; i < callbacks.Length; i++)
29+
{
30+
int index = 0;
31+
button.Click += (obj, args) => callbacks[index]();
32+
}
33+
34+
return button;
35+
}
36+
37+
public static Button OnClick(this Button button, Action callback)
38+
{
39+
button.Click += (obj, args) => callback();
40+
return button;
41+
}
42+
43+
public static Panel AddChildren(this Panel control, params Control[] children)
44+
{
45+
control.Children.AddRange(children);
46+
return control;
47+
}
48+
49+
public static ItemsControl AddItems(this ItemsControl control, params object[] items)
50+
{
51+
for (int i = 0; i < items.Length; i++)
52+
control.Items.Add(items[i]);
53+
return control;
54+
}
55+
56+
public static MenuItem AddItems(this MenuItem menu, params MenuItem[] menuItems)
57+
{
58+
for (int i = 0; i < menuItems.Length; i++)
59+
menu.Items.Add(menuItems[i]);
60+
return menu;
61+
}
62+
63+
public static TabControl AddItems(this TabControl tabControl, TabItem[] items)
64+
{
65+
for (int i = 0; i < items.Length; i++)
66+
tabControl.Items.Add(items[i]);
67+
return tabControl;
68+
}
69+
70+
public static T SetDock<T>(this T control, Dock dock) where T : Control
71+
{
72+
control.SetValue(DockPanel.DockProperty, dock);
73+
return control;
74+
}
75+
76+
public static T SetGrid<T>(this T control, int column, int row, int columnSpan = 1, int rowSpan = 1) where T : Control
77+
{
78+
if (column != 0)
79+
SetColumn(control, column);
80+
if (row != 0)
81+
SetRow(control, row);
82+
if (columnSpan != 1)
83+
SetColumnSpan(control, columnSpan);
84+
if (rowSpan != 1)
85+
SetRowSpan(control, rowSpan);
86+
return control;
87+
}
88+
89+
public static T SetColumn<T>(this T control, int value) where T : Control
90+
{
91+
control.SetValue(Grid.ColumnProperty, value);
92+
return control;
93+
}
94+
95+
public static T SetRow<T>(this T control, int value) where T : Control
96+
{
97+
control.SetValue(Grid.RowProperty, value);
98+
return control;
99+
}
100+
101+
public static T SetColumnSpan<T>(this T control, int value) where T : Control
102+
{
103+
control.SetValue(Grid.ColumnSpanProperty, value);
104+
return control;
105+
}
106+
107+
public static T SetRowSpan<T>(this T control, int value) where T : Control
108+
{
109+
control.SetValue(Grid.RowSpanProperty, value);
110+
return control;
111+
}
112+
113+
public static T SetTooltip<T>(this T control, string tooltip) where T : Control
114+
{
115+
control.SetValue(ToolTip.TipProperty, tooltip);
116+
return control;
117+
}
118+
119+
public static T OnSelectionChanged<T>(this T control, Action action) where T : SelectingItemsControl
120+
{
121+
control.SelectionChanged += (_, _) => action();
122+
return control;
123+
}
124+
}
125+
}

Counter/Counter.csproj

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<PublishAot>true</PublishAot>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Avalonia" Version="11.2.4" />
13+
<PackageReference Include="Avalonia.Desktop" Version="11.2.4" />
14+
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.4" />
15+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.4" />
16+
<PackageReference Include="Avalonia.Themes.Simple" Version="11.2.4" />
17+
<PackageReference Include="Classic.Avalonia.Theme" Version="11.2.0.7" />
18+
<PackageReference Include="Material.Avalonia" Version="3.9.2" />
19+
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
20+
<PackageReference Include="Semi.Avalonia" Version="11.2.1.4" />
21+
</ItemGroup>
22+
23+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
24+
<DefineConstants>$(DefineConstants);OS_WINDOWS</DefineConstants>
25+
</PropertyGroup>
26+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
27+
<DefineConstants>$(DefineConstants);OS_LINUX</DefineConstants>
28+
</PropertyGroup>
29+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
30+
<DefineConstants>$(DefineConstants);OS_MAC</DefineConstants>
31+
</PropertyGroup>
32+
33+
</Project>

Counter/MainViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Counter;
2+
3+
internal class MainViewModel
4+
{
5+
6+
}

0 commit comments

Comments
 (0)