https://github.com/tirsvadgui/dotnet.wpf.template
https://github.com/tirsvadgui/dotnet.wpf.template
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tirsvadgui/dotnet.wpf.template
- Owner: TirsvadGUI
- License: agpl-3.0
- Created: 2025-09-19T01:20:13.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-19T06:31:53.000Z (9 months ago)
- Last Synced: 2025-10-08T22:47:04.644Z (9 months ago)
- Language: C#
- Size: 523 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ο»Ώο»Ώ[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]
# ![Logo][logo] Dotnet.Wpf.Template
A clean WPF (.NET 9) starter focused on:
- Separation of concerns
- Dark and light themes
- Dependency Injection (DI)
- Connection strings saved encrypted. Auto popup for first time run or missing configuration.
## Table of Contents
- [About the project](#about-the-project)
- [Goals](#goals)
- [Prerequisites](#prerequisites)
- [Features](#features)
- [Quick start](#quick-start)
- [Project structure (suggested)](#project-structure-suggested)
- [Notes](#notes)
- [License](#license)
- [Contact](#contact)
- [Acknowledgements](#acknowledgements)
- [Contributing](#contributing)
## About the project
This project is a template for building WPF applications using .NET 9.
It incorporates best practices such as the MVVM pattern, dependency injection, and theme management. The template is designed to help developers get started quickly while maintaining a clean and organized codebase.
## Goals
- Provide a solid foundation for building WPF applications
- Promote best practices in software architecture
- Enable easy customization and extension
## Prerequisites
- [.NET 9 SDK](https://dotnet.microsoft.com/download/dotnet/9.0)
- Visual Studio, Visual Studio Code or other C# ide with WPF support
## Features
- WPF (.NET 9)
- MVVM pattern
- Dependency Injection (DI) with Microsoft.Extensions.DependencyInjection
- Light and dark themes with easy switching
- Connection string saved encrypted in user AppData folder
- Popup windows for first time run or missing configuration
- Project structure keeping UI, domain, and infrastructure clearly separated
## Quick start
### 1. Clone and open in Visual Studio 2022.
`git clone https://github.com/TirsvadGUI/Dotnet.Wpf.Template.git`
## Project structure (suggested)
Legend for levels and items:
- ποΈ Level 1: repository root
- π Level 2: top-level folder
- π Level 3: subfolder
- ποΈ Level 4+: deeper subfolders
- π§© Project (csproj)
- π File
- π¨ Theme resources
- βοΈ Configuration
- π§ͺ Tests
```text
ποΈ Dotnet.Wpf.Template
ββ π src
β ββ π§© Template.App (WPF UI)
β β ββ π Configuration (Popup windows for first time run or missing configuration)
β β ββ π Views (MVVM)
β β ββ π ViewModels (MVVM)
β β ββ π¨ Themes
β β β ββ π Theme.Light.xaml
β β β ββ π Theme.Dark.xaml
β β ββ π Resources (styles, converters, controls)
β β ββ π appsettings.json (optional, not for secrets)
β β ββ π appsettings.Development.json (optional, not for secrets)
β β ββ π App.xaml
β β ββ π App.xaml.cs (application bootstrap - Generic Host + DI)
β ββ π§© Template.Infrastructure (integrations)
β β ββ π Configuration (Read / Save Connection string)
β β ββ π Data (clients, context, mappers)
β β ββ π Repositories (data access)
β β ββ π Services (APIs, email, logging)
β β ββ π DependencyInjection.cs
β ββ π§© Template.Application (use cases)
β β ββ π Abstractions (interfaces)
β β ββ π DTOs (data transfer objects)
β β ββ π Services (business logic)
β β ββ π DependencyInjection.cs
β ββ π§© Template.Domain (core models)
β ββ π Models
β ββ π Abstractions (interfaces)
ββ π§ͺ tests (optional)
β ββ π§© Template.App.Tests
ββ π README.md
ββ π LICENSE.txt
```
- `App.xaml`, `App.xaml.cs` β application bootstrap (Generic Host + DI)
- `Views/`, `ViewModels/` β presentation (MVVM)
- `Infrastructure/` β external services (data access, APIs)
- `Themes/Theme.Light.xaml`, `Themes/Theme.Dark.xaml` β theme resources
- `appsettings.json` (optional, not for secrets)
- User secrets or environment variables for secrets
This keeps UI, domain, and infrastructure clearly separated.
## How it works
### Dependency Injection (DI)
In `App.xaml.cs` we build a Host and register services
- DI constructs `MainWindow` and can inject dependencies (like `MainViewModel`) into its constructor.
### MVVM in a nutshell
- View (`MainWindow.xaml`): defines the UI in XAML.
- ViewModel (`MainViewModel`): holds the data and commands (no UI code).
- Binding connects them (e.g., `{Binding Title}` displays a `Title` property from the ViewModel).
This keeps UI and logic separate and testable.
### Connection string flow
`Template.Infrastructure.Configuration.EncryptedConnectionStringProvider` tries:
1. Configuration (appsettings, env vars, or User Secrets)
2. Encrypted store (saved from a previous run)
3. UI prompt (popup) if still missing
If the popup is used and you click OK, it saves the encrypted connection string so you donβt have to enter it again.
### Themes (Light/Dark)
To use a theme, merge it in `App.xaml`:
```xml
```
## Notes
- Separation of concerns: keep UI (Views), state/logic (ViewModels), core logic (Domain), and integrations (Infrastructure) decoupled and wired via DI.
- Keep secrets out of source control; prefer environment variables or User Secrets.
## Common tasks
- Change window title: open `MainWindow.xaml` and set `Title="Your App"`.
- Add a service: register it in `App.xaml.cs` via `services.AddSingleton();`, then inject into constructors.
- Add a new View + ViewModel: create files in `Views/` and `ViewModels/`, register the View in DI if you want to resolve it from the container.
## License
## Contact
- Issues: [GitHub Issues][issues-url]
- LinkedIn: [Profile][linkedin-url]
## Acknowledgements
- .NET team and WPF community
- MVVM patterns and resources shared by the community
## Contributing
Contributions are welcome!
- Fork the repo
- Create a feature branch
- Commit changes
- Open a Pull Request
[contributors-shield]: https://img.shields.io/github/contributors/TirsvadGUI/Dotnet.Wpf.Template?style=for-the-badge
[contributors-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/TirsvadGUI/Dotnet.Wpf.Template?style=for-the-badge
[forks-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template/network/members
[stars-shield]: https://img.shields.io/github/stars/TirsvadGUI/Dotnet.Wpf.Template?style=for-the-badge
[stars-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template/stargazers
[issues-shield]: https://img.shields.io/github/issues/TirsvadGUI/Dotnet.Wpf.Template?style=for-the-badge
[issues-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template/issues
[license-shield]: https://img.shields.io/github/license/TirsvadGUI/Dotnet.Wpf.Template?style=for-the-badge
[license-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://www.linkedin.com/in/jens-TirsvadGUI-nielsen-13b795b9/
[githubIssue-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template/issues/
[repo-size-shield]: https://img.shields.io/github/repo-size/TirsvadGUI/Dotnet.Wpf.Template?style=for-the-badge
[repo-url]: https://github.com/TirsvadGUI/Dotnet.Wpf.Template.git
[logo]: https://raw.githubusercontent.com/TirsvadGUI/Dotnet.Wpf.Template/master/images/logo/32x32/logo.png