Skip to content

Commit

Permalink
Upgrade to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelGirodon committed Mar 24, 2024
1 parent 7ae164c commit ab0ed55
Show file tree
Hide file tree
Showing 13 changed files with 1,241 additions and 1,274 deletions.
10 changes: 5 additions & 5 deletions Accounts/Accounts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<PropertyGroup>
<!-- Target configuration -->
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<!-- Assembly metadata -->
<AssemblyVersion>0.1.0</AssemblyVersion>
<FileVersion>0.1.0</FileVersion>
<AssemblyVersion>0.2.0</AssemblyVersion>
<FileVersion>0.2.0</FileVersion>
<ApplicationIcon>Images\Icon.ico</ApplicationIcon>
<!-- Package metadata -->
<Title>Accounts</Title>
<PackageVersion>0.1.0</PackageVersion>
<PackageVersion>0.2.0</PackageVersion>
<Description>A basic personal financial-accounting software</Description>
<PackageProjectUrl>https://github.com/GaelGirodon/accounts</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/GaelGirodon/accounts/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseUrl>https://github.com/GaelGirodon/accounts/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/GaelGirodon/accounts.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
Expand Down
33 changes: 16 additions & 17 deletions Accounts/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
using System.Windows.Markup;
using Accounts.Windows;

namespace Accounts
namespace Accounts;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
private void App_OnStartup(object sender, StartupEventArgs e)
{
private void App_OnStartup(object sender, StartupEventArgs e)
{
// Set culture for WPF formats
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage
.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
// Start the main window
var window = new MainWindow();
if (e.Args.Length == 1) // Open with
window.OpenFile(e.Args[0]);
window.Show();
}
// Set culture for WPF formats
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage
.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
// Start the main window
var window = new MainWindow();
if (e.Args.Length == 1) // Open with
window.OpenFile(e.Args[0]);
window.Show();
}
}
107 changes: 52 additions & 55 deletions Accounts/Controls/AmountArrow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,65 @@
using System.Windows.Controls;
using System.Windows.Media;

namespace Accounts.Controls
namespace Accounts.Controls;

/// <summary>
/// Amount arrow control.
/// <br />
/// Displays a circle with:
/// <ul>
/// <li>A green background and an arrow pointing to the top-right corner if the amount is positive,</li>
/// <li>A red background and an arrow pointing to the bottom-right corner if the amount is negative,</li>
/// <li>A gray background and an arrow pointing to the right elsewhere.</li>
/// </ul>
/// </summary>
public partial class AmountArrow : UserControl
{
/// <summary>
/// Amount arrow control.
/// <br />
/// Displays a circle with:
/// <ul>
/// <li>A green background and an arrow pointing to the top-right corner if the amount is positive,</li>
/// <li>A red background and an arrow pointing to the bottom-right corner if the amount is negative,</li>
/// <li>A gray background and an arrow pointing to the right elsewhere.</li>
/// </ul>
/// Amount value.
/// </summary>
public partial class AmountArrow : UserControl
public decimal Amount
{
/// <summary>
/// Amount value.
/// </summary>
public decimal Amount
{
get => (decimal) GetValue(AmountProperty);
set => SetValue(AmountProperty, value);
}
get => (decimal)GetValue(AmountProperty);
set => SetValue(AmountProperty, value);
}

/// <summary>
/// Amount dependency property (allows data binding and more).
/// </summary>
public static readonly DependencyProperty AmountProperty = DependencyProperty
.Register(nameof(Amount), typeof(decimal), typeof(AmountArrow),
new UIPropertyMetadata(0m, AmountPropertyChanged));
/// <summary>
/// Amount dependency property (allows data binding and more).
/// </summary>
public static readonly DependencyProperty AmountProperty = DependencyProperty
.Register(nameof(Amount), typeof(decimal), typeof(AmountArrow),
new UIPropertyMetadata(0m, AmountPropertyChanged));

/// <summary>
/// Modify the circle background and the arrow angle
/// depending on the amount value.
/// </summary>
private static void AmountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
/// <summary>
/// Modify the circle background and the arrow angle
/// depending on the amount value.
/// </summary>
private static void AmountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var amount = e.NewValue is decimal value ? value : 0;
if (d is not AmountArrow control)
return;
control.ArrowRotation.Angle = amount switch
{
var amount = e.NewValue is decimal value ? value : 0;
if (!(d is AmountArrow control))
return;
control.ArrowRotation.Angle = amount switch
{
{ } a when a >= 0 => -45,
{ } a when a <= 0 => 45,
_ => 0
};
control.Ellipse.Fill = new SolidColorBrush(amount switch
{
{ } a when a >= 0 => Color.FromRgb(68, 189, 50),
{ } a when a <= 0 => Color.FromRgb(194, 54, 22),
_ => Colors.Gray
});
}

/// <summary>
/// Initialize the circle with a gray background
/// and an arrow pointing to the right.
/// </summary>
public AmountArrow()
>= 0 => -45,
<= 0 => 45
};
control.Ellipse.Fill = new SolidColorBrush(amount switch
{
InitializeComponent();
ArrowRotation.Angle = 0;
Ellipse.Fill = new SolidColorBrush(Colors.Gray);
}
>= 0 => Color.FromRgb(68, 189, 50),
<= 0 => Color.FromRgb(194, 54, 22)
});
}

/// <summary>
/// Initialize the circle with a gray background
/// and an arrow pointing to the right.
/// </summary>
public AmountArrow()
{
InitializeComponent();
ArrowRotation.Angle = 0;
Ellipse.Fill = new SolidColorBrush(Colors.Gray);
}
}
Loading

0 comments on commit ab0ed55

Please sign in to comment.