-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ChrisPulman/AddAvalonia
- Loading branch information
Showing
21 changed files
with
1,006 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
using Avalonia; | ||
using Avalonia.ReactiveUI; | ||
|
||
namespace XamlLEDControl.Avalonia.TestApp.Desktop; | ||
|
||
internal 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() | ||
=> AppBuilder.Configure<App>() | ||
.UsePlatformDetect() | ||
.WithInterFont() | ||
.LogToTrace() | ||
.UseReactiveUI(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/XamlLEDControl.Avalonia.TestApp.Desktop/XamlLEDControl.Avalonia.TestApp.Desktop.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects. | ||
One for Windows with net7.0-windows TFM, one for MacOS with net7.0-macos and one with net7.0 TFM for Linux.--> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\XamlLEDControl.Avalonia.TestApp\XamlLEDControl.Avalonia.TestApp.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 embeded controls. | ||
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests --> | ||
<assemblyIdentity version="1.0.0.0" name="AvaloniaTest.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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Application | ||
x:Class="XamlLEDControl.Avalonia.TestApp.App" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
RequestedThemeVariant="Default"> | ||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --> | ||
|
||
<Application.Styles> | ||
<FluentTheme /> | ||
</Application.Styles> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceInclude Source="avares://XamlLEDControl.Avalonia/XamlLED.axaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
|
||
using XamlLEDControl.Avalonia.TestApp.ViewModels; | ||
using XamlLEDControl.Avalonia.TestApp.Views; | ||
|
||
namespace XamlLEDControl.Avalonia.TestApp; | ||
|
||
/// <summary> | ||
/// App. | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
/// <summary> | ||
/// Initializes the application by loading XAML etc. | ||
/// </summary> | ||
public override void Initialize() => AvaloniaXamlLoader.Load(this); | ||
|
||
/// <summary> | ||
/// Called when [framework initialization completed]. | ||
/// </summary> | ||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
desktop.MainWindow = new MainWindow | ||
{ | ||
DataContext = new MainViewModel() | ||
}; | ||
} | ||
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) | ||
{ | ||
singleViewPlatform.MainView = new MainView | ||
{ | ||
DataContext = new MainViewModel() | ||
}; | ||
} | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} |
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
src/XamlLEDControl.Avalonia.TestApp/ViewModels/MainViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace XamlLEDControl.Avalonia.TestApp.ViewModels; | ||
|
||
/// <summary> | ||
/// MainViewModel. | ||
/// </summary> | ||
/// <seealso cref="XamlLEDControl.Avalonia.TestApp.ViewModels.ViewModelBase" /> | ||
public class MainViewModel : ViewModelBase | ||
{ | ||
/// <summary> | ||
/// Gets the greeting. | ||
/// </summary> | ||
/// <value> | ||
/// The greeting. | ||
/// </value> | ||
public string Greeting => "Welcome to Avalonia!"; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/XamlLEDControl.Avalonia.TestApp/ViewModels/ViewModelBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using ReactiveUI; | ||
|
||
namespace XamlLEDControl.Avalonia.TestApp.ViewModels; | ||
|
||
/// <summary> | ||
/// ViewModelBase. | ||
/// </summary> | ||
/// <seealso cref="ReactiveUI.ReactiveObject" /> | ||
public class ViewModelBase : ReactiveObject | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<UserControl | ||
x:Class="XamlLEDControl.Avalonia.TestApp.Views.MainView" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:led="https://github.com/ChrisPulman/XamlLEDControl.Avalonia" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:vm="clr-namespace:XamlLEDControl.Avalonia.TestApp.ViewModels" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
x:DataType="vm:MainViewModel" | ||
mc:Ignorable="d"> | ||
<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:MainViewModel /> | ||
</Design.DataContext> | ||
<Grid> | ||
<StackPanel | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Orientation="Horizontal"> | ||
<led:XamlLED | ||
x:Name="led1" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
ActiveLed="1" | ||
FontSize="22" | ||
LEDSize="50" | ||
LedOrientation="Vertical" | ||
Text="I Am An LED" | ||
TextPosition="Left" /> | ||
<led:XamlLED | ||
x:Name="led" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
ActiveLed="1" | ||
FontSize="22" | ||
LEDSize="50" | ||
LedOrientation="Vertical" | ||
Text="I Am An LED Cluster" | ||
TextPosition="Left" /> | ||
|
||
</StackPanel> | ||
|
||
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Bottom"> | ||
<CheckBox | ||
x:Name="chkBox" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Bottom" | ||
Content="Use Boolean" /> | ||
<Button | ||
Width="100" | ||
Height="100" | ||
Click="Button_Click" /> | ||
</StackPanel> | ||
|
||
</Grid> | ||
|
||
</UserControl> |
47 changes: 47 additions & 0 deletions
47
src/XamlLEDControl.Avalonia.TestApp/Views/MainView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Media; | ||
|
||
namespace XamlLEDControl.Avalonia.TestApp.Views; | ||
|
||
/// <summary> | ||
/// MainView. | ||
/// </summary> | ||
public partial class MainView : UserControl | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MainView"/> class. | ||
/// </summary> | ||
public MainView() | ||
{ | ||
InitializeComponent(); | ||
led.LedOnColors = new List<Color>(new[] { Colors.Green, Colors.Red, Colors.Green, Colors.Red }); | ||
led.LedOffColors = new List<Color>(new[] { Colors.DarkRed, Colors.DarkGreen, Colors.DarkRed, Colors.DarkGreen }); | ||
led1.LedOnColors = new List<Color>(new[] { Colors.Green }); | ||
led1.LedOffColors = new List<Color>(new[] { Colors.Red }); | ||
} | ||
|
||
private void Button_Click(object? sender, RoutedEventArgs e) | ||
{ | ||
if (chkBox.IsChecked == true) | ||
{ | ||
led.IsTrue = !led.IsTrue; | ||
} | ||
else | ||
{ | ||
led.IsTrue = false; | ||
led.ActiveLed++; | ||
if (led.ActiveLed > 4) | ||
{ | ||
led.ActiveLed = 0; | ||
} | ||
} | ||
|
||
led1.IsTrue = !led1.IsTrue; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/XamlLEDControl.Avalonia.TestApp/Views/MainWindow.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:vm="using:XamlLEDControl.Avalonia.TestApp.ViewModels" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:views="clr-namespace:XamlLEDControl.Avalonia.TestApp.Views" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="XamlLEDControl.Avalonia.TestApp.Views.MainWindow" | ||
Icon="/Assets/avalonia-logo.ico" | ||
Title="XamlLEDControl.Avalonia.TestApp"> | ||
<views:MainView /> | ||
</Window> |
17 changes: 17 additions & 0 deletions
17
src/XamlLEDControl.Avalonia.TestApp/Views/MainWindow.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Avalonia.Controls; | ||
|
||
namespace XamlLEDControl.Avalonia.TestApp.Views; | ||
|
||
/// <summary> | ||
/// MainWindow. | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MainWindow"/> class. | ||
/// </summary> | ||
public MainWindow() => InitializeComponent(); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/XamlLEDControl.Avalonia.TestApp/XamlLEDControl.Avalonia.TestApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> | ||
<NoWarn>$(NoWarn);CA1822</NoWarn> | ||
</PropertyGroup> | ||
|
||
|
||
<ItemGroup> | ||
<AvaloniaResource Include="Assets\**" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" /> | ||
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" /> | ||
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" /> | ||
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" /> | ||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> | ||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\XamlLEDControl.Avalonia\XamlLEDControl.Avalonia.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace CP.XamlLEDControl.Avalonia; | ||
|
||
/// <summary> | ||
/// Text Position. | ||
/// </summary> | ||
public enum TextPosition | ||
{ | ||
/// <summary> | ||
/// The top. | ||
/// </summary> | ||
Top, | ||
|
||
/// <summary> | ||
/// The bottom. | ||
/// </summary> | ||
Bottom, | ||
|
||
/// <summary> | ||
/// The left. | ||
/// </summary> | ||
Left, | ||
|
||
/// <summary> | ||
/// The right. | ||
/// </summary> | ||
Right, | ||
|
||
/// <summary> | ||
/// The center. | ||
/// </summary> | ||
Center | ||
} |
Oops, something went wrong.