Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add attached property source generator #132

Merged
merged 10 commits into from
Feb 15, 2025
Merged
16 changes: 15 additions & 1 deletion Atc.Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Wpf.SourceGenerators",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Wpf.SourceGenerators.Tests", "test\Atc.Wpf.SourceGenerators.Tests\Atc.Wpf.SourceGenerators.Tests.csproj", "{6B9C0EC5-1D71-4B95-96C8-E5A7FCDF8276}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceGenerators", "SourceGenerators", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
ProjectSection(SolutionItems) = preProject
docs\SourceGenerators\AttachedProperty.md = docs\SourceGenerators\AttachedProperty.md
docs\SourceGenerators\DependencyProperty.md = docs\SourceGenerators\DependencyProperty.md
docs\SourceGenerators\ViewModel.md = docs\SourceGenerators\ViewModel.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mvvm", "Mvvm", "{02E4711C-F1F1-4682-8111-47957F772DDD}"
ProjectSection(SolutionItems) = preProject
docs\Mvvm\@Readme.md = docs\Mvvm\@Readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -111,9 +123,11 @@ Global
{F4BE59B5-26CB-46DB-B290-2049EF656693} = {0FA723AA-8BA7-42AD-9C08-6491F364A258}
{104F4D6B-3991-4FBA-9234-0B37DF6BB292} = {0FA723AA-8BA7-42AD-9C08-6491F364A258}
{6B9C0EC5-1D71-4B95-96C8-E5A7FCDF8276} = {2C893B25-2401-44B7-9FDA-7DC496C00D2B}
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {133AFD8A-A870-41D7-8A97-763A36D2502A}
{02E4711C-F1F1-4682-8111-47957F772DDD} = {133AFD8A-A870-41D7-8A97-763A36D2502A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7A92D7EC-F444-456B-A86C-D6683E016C35}
RESX_Rules = {"EnabledRules":["StringFormat","WhiteSpaceLead","WhiteSpaceTail","PunctuationTail"]}
SolutionGuid = {7A92D7EC-F444-456B-A86C-D6683E016C35}
EndGlobalSection
EndGlobal
178 changes: 66 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ This is a base libraries for building WPF application with the MVVM design patte
- [Table of contents](#table-of-contents)
- [Requirements](#requirements)
- [NuGet Packages Provided in this Repository](#nuget-packages-provided-in-this-repository)
- [Demonstration Application](#demonstration-application)
- [Playground and Viewer for a Given Control or Functionality](#playground-and-viewer-for-a-given-control-or-functionality)
- [🔎 Demonstration Application](#-demonstration-application)
- [Playground and Viewer for a Given Control or Functionality](#playground-and-viewer-for-a-given-control-or-functionality)
- [Initial glimpse at the demonstration application](#initial-glimpse-at-the-demonstration-application)
- [How to get started with atc-wpf](#how-to-get-started-with-atc-wpf)
- [Readme's for each NuGet Package area](#readmes-for-each-nuget-package-area)
- [Atc.Wpf](#atcwpf)
- [Controls](#controls)
- [Misc](#misc)
- [Atc.Wpf.Controls](#atcwpfcontrols)
- [Controls](#controls-1)
- [Misc](#misc-1)
- [Atc.Wpf.FontIcons](#atcwpffonticons)
- [Misc](#misc-2)
- [Atc.Wpf.Theming](#atcwpftheming)
- [How to contribute](#how-to-contribute)
- [🚀 How to get started with atc-wpf](#-how-to-get-started-with-atc-wpf)
- [WPF with MVVM Easily Separate UI and Business Logic](#wpf-with-mvvm-easily-separate-ui-and-business-logic)
- [📝 Readme's for each NuGet Package area](#-readmes-for-each-nuget-package-area)
- [💟 Atc.Wpf](#-atcwpf)
- [Controls](#controls)
- [Misc](#misc)
- [💟 Atc.Wpf.Controls](#-atcwpfcontrols)
- [Controls](#controls-1)
- [Misc](#misc-1)
- [💟 Atc.Wpf.FontIcons](#-atcwpffonticons)
- [Misc](#misc-2)
- [💟 Atc.Wpf.Theming](#-atcwpftheming)
- [⚙️ Source Generators](#️-source-generators)
- [How to contribute](#how-to-contribute)

## Requirements

Expand All @@ -34,19 +36,19 @@ This is a base libraries for building WPF application with the MVVM design patte

| Nuget package | Description | Dependencies |
|-------------------------|-----------------------------------------------------|--------------------------------|
| Atc.Wpf | Base Controls, ValueConverters, Extensions etc. | Atc & Atc.Wpf.SourceGenerators |
| Atc.Wpf.Controls | Miscellaneous UI Controls | Atc.Wpf & Atc.Wpf.Theming |
| Atc.Wpf.Controls.Sample | Controls for creating WPF sample apps | Atc.Wpf & Atc.Wpf.Theming |
| Atc.Wpf.FontIcons | Render Svg and Img resources based on fonts | Atc.Wpf |
| Atc.Wpf.Theming | Theming for Light & Dark mode for WPF base controls | Atc.Wpf |
| 💟 Atc.Wpf | Base Controls, ValueConverters, Extensions etc. | Atc & Atc.Wpf.SourceGenerators |
| 💟 Atc.Wpf.Controls | Miscellaneous UI Controls | Atc.Wpf & Atc.Wpf.Theming |
| 💟 Atc.Wpf.Controls.Sample | Controls for creating WPF sample apps | Atc.Wpf & Atc.Wpf.Theming |
| 💟 Atc.Wpf.FontIcons | Render Svg and Img resources based on fonts | Atc.Wpf |
| 💟 Atc.Wpf.Theming | Theming for Light & Dark mode for WPF base controls | Atc.Wpf |

## Demonstration Application
# 🔎 Demonstration Application

The demonstration application, `Atc.Wpf.Sample`, functions as a control explorer.
It provides quick visualization of a given control, along with options for
copying and pasting the XAML markup and/or the C# code for how to use it.

### Playground and Viewer for a Given Control or Functionality
## Playground and Viewer for a Given Control or Functionality

The following example is taken from the ReplayCommandAsync which illustrates its usage:

Expand All @@ -70,16 +72,16 @@ The following example is taken from the ReplayCommandAsync which illustrates its
| Wpf.Theming - ImageButton ![Img](docs/images/lm-wpf-theming-imagebutton.png) | Wpf.Theming - ImageButton ![Img](docs/images/dm-wpf-theming-imagebutton.png) |
| Wpf.FontIcons - Viewer ![Img](docs/images/lm-wpf-fonicons-viewer.png) | Wpf.FontIcons - Viewer ![Img](docs/images/dm-wpf-fonicons-viewer.png) |

## How to get started with atc-wpf
# 🚀 How to get started with atc-wpf

First of all, include Nuget packages in the `.csproj` file like this:

```xml
<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.178" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.178" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.178" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.178" />
<PackageReference Include="Atc.Wpf" Version="latest" />
<PackageReference Include="Atc.Wpf.Controls" Version="latest" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="latest" />
<PackageReference Include="Atc.Wpf.Theming" Version="latest" />
</ItemGroup>
```

Expand All @@ -105,126 +107,78 @@ Then update `App.xaml` like this:

Now it is possible to use controls with theming and default WPF controls like TextBox, Button etc. with theme style.

## Readme's for each NuGet Package area
## WPF with MVVM Easily Separate UI and Business Logic

With the `Atc.Wpf`, package, it is very easy to get startet with the nice `MVVM pattern`

Please read more here:

- [MVVM framework](docs/Mvvm/@Readme.md)
- [Observerble properties](docs/Mvvm/@Readme.md)
- [RelayCommands](docs/Mvvm/@Readme.md)

# 📝 Readme's for each NuGet Package area

***Note: Right now, it is a limit amount of controls and components there is documented with a `Readme.md` file.
Therefore run the `Atc.Wpf.Sample` application to explore all the controls and components.*** :-)
Therefore run the `Atc.Wpf.Sample` application to explore all the controls and components.*** 😊

### Atc.Wpf
## 💟 Atc.Wpf

#### Controls
### Controls

- [GridEx](src/Atc.Wpf/Controls/Layouts/GridEx_Readme.md)
- [StaggeredPanel](src/Atc.Wpf/Controls/Layouts/StaggeredPanel_Readme.md)
- [UniformSpacingPanel](src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel_Readme.md)
- [SvgImage](src/Atc.Wpf/Controls/Media/SvgImage_Readme.md)
- Control Helpers
- Layouts
- [GridEx](src/Atc.Wpf/Controls/Layouts/GridEx_Readme.md)
- [StaggeredPanel](src/Atc.Wpf/Controls/Layouts/StaggeredPanel_Readme.md)
- [UniformSpacingPanel](src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel_Readme.md)
- Media
- [SvgImage](src/Atc.Wpf/Controls/Media/SvgImage_Readme.md)
- Helpers
- [PanelHelper](src/Atc.Wpf/Helpers/PanelHelper_Readme.md)

#### Misc
### Misc

- [MVVM framework](src/Atc.Wpf/Mvvm/@Readme.md)
- [RelayCommand's](src/Atc.Wpf/Command/@Readme.md)
- [ShaderEffects](src/Atc.Wpf/Media/ShaderEffects/@Readme.md)
- [How to use HLSL Shader Compiler](src/Atc.Wpf/Media/ShaderEffects/Shaders/@Readme.md)
- [Tranlation & localizaion](src/Atc.Wpf/Translation/@Readme.md)
- [ValueConverters](src/Atc.Wpf/ValueConverters/@Readme.md)

### Atc.Wpf.Controls
## 💟 Atc.Wpf.Controls

#### Controls
### Controls

- [WellKnownColorPicker](src/Atc.Wpf.Controls/ColorControls/WellKnownColorPicker_Readme.md)

#### Misc
### Misc

- [ValueConverters](src/Atc.Wpf.Controls/ValueConverters/@Readme.md)

### Atc.Wpf.FontIcons
## 💟 Atc.Wpf.FontIcons

#### Misc
### Misc

- [ValueConverters](src/Atc.Wpf.FontIcons/ValueConverters/@Readme.md)

### Atc.Wpf.Theming
## 💟 Atc.Wpf.Theming

- [ValueConverters](src/Atc.Wpf.Theming/ValueConverters/@Readme.md)

### Source Generators
# ⚙️ Source Generators

In MVVM, certain attributes help automate boilerplate code using source generators.
In for WPF, certain attributes help automate boilerplate code using source generators.

Example for ViewModel classes
Read more about here:

![MVVM Source Generation](docs/images/mvvm-source-generated.png)

For more details, see the [MVVM](src/Atc.Wpf/Mvvm/@Readme.md) section.
- [SourceGenerators for AttachedProperties](docs/SourceGenerators/AttachedProperty.md)
- [SourceGenerators for DependencyProperties](docs/SourceGenerators/DependencyProperty.md)
- [SourceGenerators for ViewModel](docs/SourceGenerators/ViewModel.md)

### DependencyProperty
Example for ViewModel classes

### Human made Code for complex property

```csharp
[DependencyProperty<bool>("IsRunning")]
public partial class MyControl : UserControl
{
}
```

### Human made Code for simple property

```csharp
[DependencyProperty<bool>("IsRunning"]
public partial class MyControl : UserControl
{
}
```

### Generated Code for simple property

```csharp
public partial class MyControl
{
public static readonly DependencyProperty IsRunningProperty = DependencyProperty.Register(
nameof(IsRunning),
typeof(bool),
typeof(MyControl),
new FrameworkPropertyMetadata(defaultValue: BooleanBoxes.TrueBox);

public bool IsRunning
{
get => (bool)GetValue(IsRunningProperty);
set => SetValue(IsRunningProperty, value);
}
}
```
![MVVM Source Generation](docs/images/mvvm-source-generated.png)

### Generated Code for complex property

```csharp
public partial class MyControl
{
public static readonly DependencyProperty IsRunningProperty = DependencyProperty.Register(
nameof(IsRunning),
typeof(bool),
typeof(MyControl),
new FrameworkPropertyMetadata(
defaultValue: BooleanBoxes.TrueBox,
propertyChangedCallback: PropertyChangedCallback,
coerceValueCallback: CoerceValueCallback,
flags: FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
defaultUpdateSourceTrigger: UpdateSourceTrigger.Default,
isAnimationProhibited: true));

public bool IsRunning
{
get => (bool)GetValue(IsRunningProperty);
set => SetValue(IsRunningProperty, value);
}
}
```
For more details, see the [MVVM](docs/Mvvm/@Readme.md) section.

## How to contribute
# How to contribute

[Contribution Guidelines](https://atc-net.github.io/introduction/about-atc#how-to-contribute)

Expand Down
50 changes: 50 additions & 0 deletions docs/Mvvm/@Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# MVVM in WPF

Windows Presentation Foundation (WPF) fully supports the **Model-View-ViewModel (MVVM)** pattern, which promotes a clear separation of concerns between the UI and business logic.

The **Atc.Wpf** library provides a robust foundation for implementing MVVM effectively, reducing boilerplate code and simplifying development.

## Features

The `Atc.Wpf` library offers a variety of base classes and utilities to streamline MVVM implementation:

| Component | Description |
|---------------------------|--------------------------------------------------------------------------------|
| `ViewModelBase` | A base class for ViewModels. |
| `MainWindowViewModelBase` | A base class for the main window ViewModel. |
| `ViewModelDialogBase` | A base class for dialog ViewModels. |
| `ObservableObject` | A base class for observable objects implementing `INotifyPropertyChanged`. |
| `RelayCommand` | A command supporting `CanExecute`. |
| `RelayCommand<T>` | A command with a generic parameter and `CanExecute`. |
| `RelayCommandAsync` | An asynchronous command supporting `CanExecute`. |
| `RelayCommandAsync<T>` | An asynchronous command with a generic parameter and `CanExecute`. |

For detailed information about commands, refer to the [RelayCommand documentation](../SourceGenerators/ViewModel.md).

---

### Getting started using `ViewModelBase`

Below is a simple example demonstrating how to create a ViewModel using `ViewModelBase`:

```csharp
public class MyViewModel : ViewModelBase
{
private string myProperty;

public string MyProperty
{
get => myProperty;
set
{
if (myProperty == value)
{
return;
}

myProperty = value;
RaisePropertyChanged();
}
}
}
```
Loading
Loading