Skip to content

Commit 4c5a4b0

Browse files
committed
1 parent 0095603 commit 4c5a4b0

File tree

16 files changed

+744
-0
lines changed

16 files changed

+744
-0
lines changed

AvaloniaIDemo/TouchSizeAvalonia/.gitignore

Lines changed: 454 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Nullable>enable</Nullable>
4+
<AvaloniaVersion>11.1.0</AvaloniaVersion>
5+
</PropertyGroup>
6+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
using Avalonia;
4+
using Avalonia.ReactiveUI;
5+
6+
namespace TouchSizeAvalonia.Desktop;
7+
8+
class Program
9+
{
10+
// Initialization code. Don't use any Avalonia, third-party APIs or any
11+
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
12+
// yet and stuff might break.
13+
[STAThread]
14+
public static void Main(string[] args) => BuildAvaloniaApp()
15+
.StartWithClassicDesktopLifetime(args);
16+
17+
// Avalonia configuration, don't remove; also used by visual designer.
18+
public static AppBuilder BuildAvaloniaApp()
19+
=> AppBuilder.Configure<App>()
20+
.UsePlatformDetect()
21+
.WithInterFont()
22+
.LogToTrace()
23+
.UseReactiveUI();
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
5+
One for Windows with net8.0-windows TFM, one for MacOS with net8.0-macos and one with net8.0 TFM for Linux.-->
6+
<TargetFramework>net8.0</TargetFramework>
7+
<Nullable>enable</Nullable>
8+
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
9+
<ApplicationManifest>app.manifest</ApplicationManifest>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\TouchSizeAvalonia\TouchSizeAvalonia.csproj" />
18+
</ItemGroup>
19+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<!-- This manifest is used on Windows only.
4+
Don't remove it as it might cause problems with window transparency and embeded controls.
5+
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
6+
<assemblyIdentity version="1.0.0.0" name="AvaloniaTest.Desktop"/>
7+
8+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
9+
<application>
10+
<!-- A list of the Windows versions that this application has been tested on
11+
and is designed to work with. Uncomment the appropriate elements
12+
and Windows will automatically select the most compatible environment. -->
13+
14+
<!-- Windows 10 -->
15+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
16+
</application>
17+
</compatibility>
18+
</assembly>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.10.35013.160
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TouchSizeAvalonia", "TouchSizeAvalonia\TouchSizeAvalonia.csproj", "{285006F8-444E-4C1E-A0F1-64B9AA9EDE1B}"
6+
EndProject
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TouchSizeAvalonia.Desktop", "TouchSizeAvalonia.Desktop\TouchSizeAvalonia.Desktop.csproj", "{6270DC07-E452-4360-98C4-8C1DB8F283CB}"
8+
EndProject
9+
Global
10+
GlobalSection(ExtensibilityGlobals) = postSolution
11+
SolutionGuid = {4C407C1B-56F3-432F-988B-4153C3E17FAD}
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{285006F8-444E-4C1E-A0F1-64B9AA9EDE1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{285006F8-444E-4C1E-A0F1-64B9AA9EDE1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{285006F8-444E-4C1E-A0F1-64B9AA9EDE1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{285006F8-444E-4C1E-A0F1-64B9AA9EDE1B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{6270DC07-E452-4360-98C4-8C1DB8F283CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{6270DC07-E452-4360-98C4-8C1DB8F283CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{6270DC07-E452-4360-98C4-8C1DB8F283CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{6270DC07-E452-4360-98C4-8C1DB8F283CB}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
24+
Debug|Any CPU = Debug|Any CPU
25+
Release|Any CPU = Release|Any CPU
26+
EndGlobalSection
27+
GlobalSection(SolutionProperties) = preSolution
28+
HideSolutionNode = FALSE
29+
EndGlobalSection
30+
EndGlobal
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
x:Class="TouchSizeAvalonia.App"
4+
RequestedThemeVariant="Default">
5+
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
6+
7+
<Application.Styles>
8+
<FluentTheme />
9+
</Application.Styles>
10+
</Application>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Avalonia;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using Avalonia.Markup.Xaml;
4+
5+
using TouchSizeAvalonia.ViewModels;
6+
using TouchSizeAvalonia.Views;
7+
8+
namespace TouchSizeAvalonia;
9+
10+
public partial class App : Application
11+
{
12+
public override void Initialize()
13+
{
14+
AvaloniaXamlLoader.Load(this);
15+
}
16+
17+
public override void OnFrameworkInitializationCompleted()
18+
{
19+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
20+
{
21+
desktop.MainWindow = new MainWindow
22+
{
23+
DataContext = new MainViewModel()
24+
};
25+
}
26+
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
27+
{
28+
singleViewPlatform.MainView = new MainView
29+
{
30+
DataContext = new MainViewModel()
31+
};
32+
}
33+
34+
base.OnFrameworkInitializationCompleted();
35+
}
36+
}
Binary file not shown.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<Nullable>enable</Nullable>
5+
<LangVersion>latest</LangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<AvaloniaResource Include="Assets\**" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
14+
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
15+
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" />
16+
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
17+
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
18+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<Reference Include="Avalonia">
23+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.dll</HintPath>
24+
</Reference>
25+
<Reference Include="Avalonia.Base">
26+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Base.dll</HintPath>
27+
</Reference>
28+
<Reference Include="Avalonia.Build.Tasks">
29+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Build.Tasks.dll</HintPath>
30+
</Reference>
31+
<Reference Include="Avalonia.Controls">
32+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Controls.dll</HintPath>
33+
</Reference>
34+
<Reference Include="Avalonia.DesignerSupport">
35+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.DesignerSupport.dll</HintPath>
36+
</Reference>
37+
<Reference Include="Avalonia.Dialogs">
38+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Dialogs.dll</HintPath>
39+
</Reference>
40+
<Reference Include="Avalonia.FreeDesktop">
41+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.FreeDesktop.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Avalonia.Markup">
44+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Markup.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Avalonia.Markup.Xaml">
47+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Markup.Xaml.dll</HintPath>
48+
</Reference>
49+
<Reference Include="Avalonia.Metal">
50+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Metal.dll</HintPath>
51+
</Reference>
52+
<Reference Include="Avalonia.MicroCom">
53+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.MicroCom.dll</HintPath>
54+
</Reference>
55+
<Reference Include="Avalonia.OpenGL">
56+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.OpenGL.dll</HintPath>
57+
</Reference>
58+
<Reference Include="Avalonia.Remote.Protocol">
59+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Remote.Protocol.dll</HintPath>
60+
</Reference>
61+
<Reference Include="Avalonia.Skia">
62+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Skia.dll</HintPath>
63+
</Reference>
64+
<Reference Include="Avalonia.Vulkan">
65+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.Vulkan.dll</HintPath>
66+
</Reference>
67+
<Reference Include="Avalonia.X11">
68+
<HintPath>..\..\..\..\..\..\Library\Avalonia\Avalonia.X11.dll</HintPath>
69+
</Reference>
70+
</ItemGroup>
71+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace TouchSizeAvalonia.ViewModels;
2+
3+
public class MainViewModel : ViewModelBase
4+
{
5+
public string Greeting => "Welcome to Avalonia!";
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using ReactiveUI;
2+
3+
namespace TouchSizeAvalonia.ViewModels;
4+
5+
public class ViewModelBase : ReactiveObject
6+
{
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:vm="clr-namespace:TouchSizeAvalonia.ViewModels"
6+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
7+
x:Class="TouchSizeAvalonia.Views.MainView"
8+
x:DataType="vm:MainViewModel">
9+
<Design.DataContext>
10+
<!-- This only sets the DataContext for the previewer in an IDE,
11+
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
12+
<vm:MainViewModel />
13+
</Design.DataContext>
14+
15+
<Grid Background="Transparent">
16+
<TextBlock x:Name="MessageTextBlock" Margin="10,10,10,10" IsHitTestVisible="False" TextWrapping="Wrap"></TextBlock>
17+
</Grid>
18+
</UserControl>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
4+
namespace TouchSizeAvalonia.Views;
5+
6+
public partial class MainView : UserControl
7+
{
8+
public MainView()
9+
{
10+
InitializeComponent();
11+
this.PointerMoved += MainView_PointerMoved;
12+
}
13+
14+
private void MainView_PointerMoved(object? sender, Avalonia.Input.PointerEventArgs e)
15+
{
16+
var currentPoint = e.GetCurrentPoint(null);
17+
var position = currentPoint.Position;
18+
dynamic d = currentPoint.Properties;
19+
Rect contactRect = d.ContactRect;
20+
MessageTextBlock.Text = $"X: {position.X}, Y: {position.Y} WH={contactRect.Width},{contactRect.Height}";
21+
}
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Window xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:vm="using:TouchSizeAvalonia.ViewModels"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:views="clr-namespace:TouchSizeAvalonia.Views"
7+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
8+
x:Class="TouchSizeAvalonia.Views.MainWindow"
9+
Icon="/Assets/avalonia-logo.ico"
10+
Title="TouchSizeAvalonia">
11+
<views:MainView />
12+
</Window>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Avalonia.Controls;
2+
3+
namespace TouchSizeAvalonia.Views;
4+
5+
public partial class MainWindow : Window
6+
{
7+
public MainWindow()
8+
{
9+
InitializeComponent();
10+
}
11+
}

0 commit comments

Comments
 (0)