CG.Platform.Presentation
3.10.6
dotnet add package CG.Platform.Presentation --version 3.10.6
NuGet\Install-Package CG.Platform.Presentation -Version 3.10.6
<PackageReference Include="CG.Platform.Presentation" Version="3.10.6" />
<PackageVersion Include="CG.Platform.Presentation" Version="3.10.6" />
<PackageReference Include="CG.Platform.Presentation" />
paket add CG.Platform.Presentation --version 3.10.6
#r "nuget: CG.Platform.Presentation, 3.10.6"
#:package CG.Platform.Presentation@3.10.6
#addin nuget:?package=CG.Platform.Presentation&version=3.10.6
#tool nuget:?package=CG.Platform.Presentation&version=3.10.6
Platform.Presentation
A WPF presentation library that provides base view models, custom controls, and theme management capabilities.
Features
- Base View Models: Common MVVM patterns and base classes
- Custom Controls: Reusable WPF controls
- Theme Management: Dynamic MahApps.Metro theme switching
- Culture Management: Multi-language support with culture switching
- Settings Persistence: Application settings management with JSON storage
Getting Started
Installation
dotnet add package CG.Platform.Presentation
Basic Setup
<Application x:Class="YourApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
// Program.cs or App.xaml.cs
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Platform.Presentation.Extensions;
var services = new ServiceCollection();
// Add logging
services.AddLogging(builder =>
{
builder.AddConsole();
builder.AddDebug();
});
// Register platform services (includes theme, culture, and settings services)
services.RegisterPlatformServices(configuration);
var serviceProvider = services.BuildServiceProvider();
Theme Management
The library provides dynamic theme switching using MahApps.Metro themes.
Available Themes
- Light Themes: Light.Blue, Light.Green, Light.Orange, Light.Purple, Light.Red, Light.Steel
- Dark Themes: Dark.Blue, Dark.Green, Dark.Orange, Dark.Purple, Dark.Red, Dark.Steel
Using Theme Service
public class MainViewModel
{
private readonly IThemeService _themeService;
public MainViewModel(IThemeService themeService)
{
_themeService = themeService;
}
public void SwitchToDarkTheme()
{
_themeService.SetTheme("Dark.Blue");
}
public IEnumerable<string> GetAvailableThemes()
{
return _themeService.GetAvailableThemes();
}
}
Theme Switching in XAML
<ComboBox ItemsSource="{Binding AvailableThemes}"
SelectedItem="{Binding SelectedTheme}"
SelectionChanged="OnThemeChanged" />
Culture Management
The library supports multi-language applications with culture switching.
Supported Cultures
- English: en-US, en-GB
- Spanish: es-ES, es-MX
- French: fr-FR, fr-CA
- German: de-DE, de-AT
- Italian: it-IT
- Portuguese: pt-BR, pt-PT
- Russian: ru-RU
- Asian Languages: ja-JP, ko-KR, zh-CN, zh-TW
Using Culture Service
public class MainViewModel
{
private readonly ICultureService _cultureService;
public MainViewModel(ICultureService cultureService)
{
_cultureService = cultureService;
}
public void SwitchToSpanish()
{
_cultureService.SetCulture("es-ES");
}
public IEnumerable<CultureInfo> GetAvailableCultures()
{
return _cultureService.GetAvailableCultures();
}
}
Settings Management
The library provides persistent application settings with JSON storage.
Using Settings Service
public class MainViewModel
{
private readonly ISettingsService _settingsService;
public MainViewModel(ISettingsService settingsService)
{
_settingsService = settingsService;
// Load saved settings
var savedTheme = _settingsService.GetSetting("SelectedTheme", "Light.Blue");
var savedLanguage = _settingsService.GetSetting("SelectedLanguage", "en-US");
}
public void SaveSettings()
{
_settingsService.SetSetting("SelectedTheme", "Dark.Blue");
_settingsService.SetSetting("SelectedLanguage", "es-ES");
_settingsService.SaveSettings();
}
}
Settings Flyout
The library includes a pre-built settings flyout for theme and culture management.
Using Settings Flyout
<mah:Flyout Header="Settings"
Position="Right"
IsOpen="{Binding IsSettingsOpen}">
<views:SettingsFlyoutView />
</mah:Flyout>
public class MainViewModel
{
public bool IsSettingsOpen { get; set; }
public void OpenSettings()
{
IsSettingsOpen = true;
}
}
Service Registration
All services are automatically registered when using RegisterPlatformServices()
:
IThemeService
→ThemeService
ICultureService
→CultureService
ISettingsService
→SettingsService
SettingsFlyoutViewModel
Configuration
Settings are automatically stored in the user's AppData folder:
- Path:
%APPDATA%\Platform.Presentation\settings.json
- Format: JSON with automatic serialization/deserialization
Dependencies
- MahApps.Metro: For theme support and Metro-style controls
- CommunityToolkit.Mvvm: For MVVM patterns and commands
- Microsoft.Extensions.Logging: For logging support
- System.Text.Json: For settings persistence
Examples
See the SettingsFlyoutView
and SettingsFlyoutViewModel
for a complete example of theme and culture management in a WPF application.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0-windows7.0 is compatible. net10.0-windows was computed. |
-
net9.0-windows7.0
- CG.Infrastructure.Core (>= 3.10.8)
- CG.Infrastructure.Navigation (>= 3.10.3)
- CG.Infrastructure.Presentation (>= 3.10.5)
- CommunityToolkit.Mvvm (>= 8.4.0)
- MahApps.Metro (>= 2.4.10)
- Microsoft.Extensions.DependencyInjection (>= 9.0.8)
- Microsoft.Extensions.Hosting (>= 9.0.8)
- Microsoft.Extensions.Logging (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.10.6 | 62 | 8/16/2025 |
3.10.5 | 60 | 8/16/2025 |
3.10.4 | 99 | 8/15/2025 |
3.10.3 | 128 | 8/14/2025 |
3.0.0 | 67 | 7/18/2025 |
2.9.0 | 133 | 12/10/2024 |
2.0.4 | 173 | 8/19/2024 |
2.0.3 | 148 | 8/19/2024 |
2.0.2 | 162 | 8/19/2024 |
2.0.1 | 174 | 8/18/2024 |
2.0.0 | 168 | 8/18/2024 |
1.0.2 | 522 | 7/13/2022 |
1.0.1 | 464 | 7/13/2022 |
1.0.0 | 468 | 7/13/2022 |