-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fbce60
commit 15125fe
Showing
33 changed files
with
1,144 additions
and
1 deletion.
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
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 @@ | ||
<Application x:Class="Galery.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
DispatcherUnhandledException="OnDispatcherUnhandledException" | ||
Exit="OnExit" | ||
Startup="OnStartup"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<FlowDirection x:Key="MainDirection">LeftToRight</FlowDirection> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ui:ThemesDictionary Theme="Light" /> | ||
<ui:ControlsDictionary /> | ||
</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,112 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors. | ||
// All Rights Reserved. | ||
|
||
using Galery.Services; | ||
using Galery.ViewModels.Pages; | ||
using Galery.ViewModels.Windows; | ||
using Galery.Views.Pages; | ||
using Galery.Views.Windows; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Lepo.i18n.DependencyInjection; | ||
using Lepo.i18n.Json; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Windows.Threading; | ||
using Wpf.Ui; | ||
using System.Globalization; | ||
using Newtonsoft.Json; | ||
using Galery.Models; | ||
|
||
namespace Galery; | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App | ||
{ | ||
// The.NET Generic Host provides dependency injection, configuration, logging, and other services. | ||
// https://docs.microsoft.com/dotnet/core/extensions/generic-host | ||
// https://docs.microsoft.com/dotnet/core/extensions/dependency-injection | ||
// https://docs.microsoft.com/dotnet/core/extensions/configuration | ||
// https://docs.microsoft.com/dotnet/core/extensions/logging | ||
private static readonly IHost _host = Host | ||
.CreateDefaultBuilder() | ||
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); }) | ||
.ConfigureServices((context, services) => | ||
{ | ||
_ = services.AddStringLocalizer(b => | ||
{ | ||
_ = b.FromJson(Assembly.GetExecutingAssembly(), "Resources.Translations-fa-IR.json", new CultureInfo("fa-IR")); | ||
_ = b.FromJson(Assembly.GetExecutingAssembly(), "Resources.Translations-en-US.json", new CultureInfo("en-US")); | ||
var cul = new CultureInfo((JsonConvert.DeserializeObject<LanInfo>(File.ReadAllText(@"CultureInfos.json")).CultureInfo)); | ||
b.SetCulture(cul); | ||
Application.Current.Resources["MainDirection"] = cul.EnglishName == "English (United States)" ? FlowDirection.LeftToRight : FlowDirection.RightToLeft; | ||
}); | ||
|
||
|
||
_ = services.AddHostedService<ApplicationHostService>(); | ||
|
||
// Page resolver service | ||
_ = services.AddSingleton<IPageService, PageService>(); | ||
|
||
// Theme manipulation | ||
_ = services.AddSingleton<IThemeService, ThemeService>(); | ||
|
||
// TaskBar manipulation | ||
_ = services.AddSingleton<ITaskBarService, TaskBarService>(); | ||
|
||
// Service containing navigation, same as INavigationWindow... but without window | ||
_ = services.AddSingleton<INavigationService, NavigationService>(); | ||
|
||
// Main window with navigation | ||
_ = services.AddSingleton<INavigationWindow, MainWindow>(); | ||
_ = services.AddSingleton<MainWindowViewModel>(); | ||
|
||
_ = services.AddSingleton<DashboardPage>(); | ||
_ = services.AddSingleton<DashboardViewModel>(); | ||
_ = services.AddTransient<DataPage>(); | ||
_ = services.AddTransient<DataViewModel>(); | ||
_ = services.AddSingleton<SettingsPage>(); | ||
_ = services.AddSingleton<SettingsViewModel>(); | ||
}).Build(); | ||
|
||
/// <summary> | ||
/// Gets registered service. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the service to get.</typeparam> | ||
/// <returns>Instance of the service or <see langword="null"/>.</returns> | ||
public static T GetService<T>() | ||
where T : class | ||
{ | ||
return _host.Services.GetService(typeof(T)) as T; | ||
} | ||
|
||
/// <summary> | ||
/// Occurs when the application is loading. | ||
/// </summary> | ||
private void OnStartup(object sender, StartupEventArgs e) | ||
{ | ||
_host.Start(); | ||
} | ||
|
||
/// <summary> | ||
/// Occurs when the application is closing. | ||
/// </summary> | ||
private async void OnExit(object sender, ExitEventArgs e) | ||
{ | ||
await _host.StopAsync(); | ||
|
||
_host.Dispose(); | ||
} | ||
|
||
/// <summary> | ||
/// Occurs when an exception is thrown by an application but not handled. | ||
/// </summary> | ||
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) | ||
{ | ||
// For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0 | ||
} | ||
} |
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,15 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,3 @@ | ||
{ | ||
"CultureInfo": "en-US" | ||
} |
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,51 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
<ApplicationIcon>wpfui-icon.ico</ApplicationIcon> | ||
<UseWPF>true</UseWPF> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="wpfui-icon.ico" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Assets\wpfui-icon-256.png" /> | ||
<None Remove="Assets\wpfui-icon-1024.png" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommunityToolkit.Mvvm" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" /> | ||
<PackageReference Include="Newtonsoft.Json" /> | ||
<PackageReference Include="WPF-UI" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Lepo.i18n.DependencyInjection\Lepo.i18n.DependencyInjection.csproj" /> | ||
<ProjectReference Include="..\..\Lepo.i18n.Json\Lepo.i18n.Json.csproj" /> | ||
<ProjectReference Include="..\..\Lepo.i18n.Wpf\Lepo.i18n.Wpf.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resources\Translations-en-US.json" /> | ||
<EmbeddedResource Include="Resources\Translations-fa-IR.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Resource Include="Assets\wpfui-icon-256.png" /> | ||
<Resource Include="Assets\wpfui-icon-1024.png" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="CultureInfos.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</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,39 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Globalization; | ||
using System.Windows.Data; | ||
using Wpf.Ui.Appearance; | ||
|
||
namespace Galery.Helpers; | ||
internal class EnumToBooleanConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (parameter is not String enumString) | ||
{ | ||
throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName"); | ||
} | ||
|
||
if (!Enum.IsDefined(typeof(ApplicationTheme), value)) | ||
{ | ||
throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum"); | ||
} | ||
|
||
var enumValue = Enum.Parse(typeof(ApplicationTheme), enumString); | ||
|
||
return enumValue.Equals(value); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (parameter is not String enumString) | ||
{ | ||
throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName"); | ||
} | ||
|
||
return Enum.Parse(typeof(ApplicationTheme), enumString); | ||
} | ||
} |
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,13 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors. | ||
// All Rights Reserved. | ||
|
||
namespace Galery.Models; | ||
|
||
public class AppConfig | ||
{ | ||
public string ConfigurationsFolder { get; set; } | ||
|
||
public string AppPropertiesFileName { get; set; } | ||
} |
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 @@ | ||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. | ||
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Windows.Media; | ||
|
||
namespace Galery.Models; | ||
public struct DataColor | ||
{ | ||
public Brush Color { get; set; } | ||
} |
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,5 @@ | ||
namespace Galery.Models; | ||
public class LanInfo | ||
{ | ||
public string CultureInfo { get; set; } = default!; | ||
} |
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,53 @@ | ||
{ | ||
"version": "1.0", | ||
"strings": [ | ||
{ | ||
"name": "Test", | ||
"value": "Text in english" | ||
}, | ||
{ | ||
"name": "Titele", | ||
"value": "WPF UI - Galery" | ||
}, | ||
{ | ||
"name": "Lan", | ||
"value": "Language" | ||
}, | ||
{ | ||
"name": "Menu.Settings", | ||
"value": "Settings" | ||
}, | ||
{ | ||
"name": "Menu.Dashboard", | ||
"value": "Dashboard" | ||
}, | ||
{ | ||
"name": "Menu.Data", | ||
"value": "Data" | ||
}, | ||
{ | ||
"name": "Menu.Search", | ||
"value": "Search" | ||
}, | ||
{ | ||
"name": "Setting.Personalization", | ||
"value": "Personalization" | ||
}, | ||
{ | ||
"name": "Setting.Theme", | ||
"value": "Theme" | ||
}, | ||
{ | ||
"name": "Setting.Theme.Light", | ||
"value": "Light" | ||
}, | ||
{ | ||
"name": "Setting.Theme.Dark", | ||
"value": "Dark" | ||
}, | ||
{ | ||
"name": "Dashboard.Click", | ||
"value": "ClickMe !" | ||
} | ||
] | ||
} |
Oops, something went wrong.