Skip to content

Commit 58cccb9

Browse files
Feature/add attached property source generator (#132)
* feat: add AttachedProperty SourceGenerator * docs: improve markdown files for control and move some to the docs folder - and ensure the sample app can reach the files * docs: improve markdown files for control and move some to the docs folder - and ensure the sample app can reach the files * feat: add support for ValidateValueCallback on Dependency and Attached property * test: add AsyncRelayCommand_NoParameter_CancellationToken * feat: improve RelayCommand for multi parameterTypes on method-target * docs: improve viewmodel * feat: improve sample of AttachedProperty * docs: update readme
1 parent 01d0a51 commit 58cccb9

File tree

63 files changed

+3161
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3161
-559
lines changed

Diff for: Atc.Wpf.sln

+15-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Wpf.SourceGenerators",
4040
EndProject
4141
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}"
4242
EndProject
43+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceGenerators", "SourceGenerators", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
44+
ProjectSection(SolutionItems) = preProject
45+
docs\SourceGenerators\AttachedProperty.md = docs\SourceGenerators\AttachedProperty.md
46+
docs\SourceGenerators\DependencyProperty.md = docs\SourceGenerators\DependencyProperty.md
47+
docs\SourceGenerators\ViewModel.md = docs\SourceGenerators\ViewModel.md
48+
EndProjectSection
49+
EndProject
50+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mvvm", "Mvvm", "{02E4711C-F1F1-4682-8111-47957F772DDD}"
51+
ProjectSection(SolutionItems) = preProject
52+
docs\Mvvm\@Readme.md = docs\Mvvm\@Readme.md
53+
EndProjectSection
54+
EndProject
4355
Global
4456
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4557
Debug|Any CPU = Debug|Any CPU
@@ -111,9 +123,11 @@ Global
111123
{F4BE59B5-26CB-46DB-B290-2049EF656693} = {0FA723AA-8BA7-42AD-9C08-6491F364A258}
112124
{104F4D6B-3991-4FBA-9234-0B37DF6BB292} = {0FA723AA-8BA7-42AD-9C08-6491F364A258}
113125
{6B9C0EC5-1D71-4B95-96C8-E5A7FCDF8276} = {2C893B25-2401-44B7-9FDA-7DC496C00D2B}
126+
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {133AFD8A-A870-41D7-8A97-763A36D2502A}
127+
{02E4711C-F1F1-4682-8111-47957F772DDD} = {133AFD8A-A870-41D7-8A97-763A36D2502A}
114128
EndGlobalSection
115129
GlobalSection(ExtensibilityGlobals) = postSolution
116-
SolutionGuid = {7A92D7EC-F444-456B-A86C-D6683E016C35}
117130
RESX_Rules = {"EnabledRules":["StringFormat","WhiteSpaceLead","WhiteSpaceTail","PunctuationTail"]}
131+
SolutionGuid = {7A92D7EC-F444-456B-A86C-D6683E016C35}
118132
EndGlobalSection
119133
EndGlobal

Diff for: README.md

+66-112
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ This is a base libraries for building WPF application with the MVVM design patte
1010
- [Table of contents](#table-of-contents)
1111
- [Requirements](#requirements)
1212
- [NuGet Packages Provided in this Repository](#nuget-packages-provided-in-this-repository)
13-
- [Demonstration Application](#demonstration-application)
14-
- [Playground and Viewer for a Given Control or Functionality](#playground-and-viewer-for-a-given-control-or-functionality)
13+
- [🔎 Demonstration Application](#-demonstration-application)
14+
- [Playground and Viewer for a Given Control or Functionality](#playground-and-viewer-for-a-given-control-or-functionality)
1515
- [Initial glimpse at the demonstration application](#initial-glimpse-at-the-demonstration-application)
16-
- [How to get started with atc-wpf](#how-to-get-started-with-atc-wpf)
17-
- [Readme's for each NuGet Package area](#readmes-for-each-nuget-package-area)
18-
- [Atc.Wpf](#atcwpf)
19-
- [Controls](#controls)
20-
- [Misc](#misc)
21-
- [Atc.Wpf.Controls](#atcwpfcontrols)
22-
- [Controls](#controls-1)
23-
- [Misc](#misc-1)
24-
- [Atc.Wpf.FontIcons](#atcwpffonticons)
25-
- [Misc](#misc-2)
26-
- [Atc.Wpf.Theming](#atcwpftheming)
27-
- [How to contribute](#how-to-contribute)
16+
- [🚀 How to get started with atc-wpf](#-how-to-get-started-with-atc-wpf)
17+
- [WPF with MVVM Easily Separate UI and Business Logic](#wpf-with-mvvm-easily-separate-ui-and-business-logic)
18+
- [📝 Readme's for each NuGet Package area](#-readmes-for-each-nuget-package-area)
19+
- [💟 Atc.Wpf](#-atcwpf)
20+
- [Controls](#controls)
21+
- [Misc](#misc)
22+
- [💟 Atc.Wpf.Controls](#-atcwpfcontrols)
23+
- [Controls](#controls-1)
24+
- [Misc](#misc-1)
25+
- [💟 Atc.Wpf.FontIcons](#-atcwpffonticons)
26+
- [Misc](#misc-2)
27+
- [💟 Atc.Wpf.Theming](#-atcwpftheming)
28+
- [⚙️ Source Generators](#️-source-generators)
29+
- [How to contribute](#how-to-contribute)
2830

2931
## Requirements
3032

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

3537
| Nuget package | Description | Dependencies |
3638
|-------------------------|-----------------------------------------------------|--------------------------------|
37-
| Atc.Wpf | Base Controls, ValueConverters, Extensions etc. | Atc & Atc.Wpf.SourceGenerators |
38-
| Atc.Wpf.Controls | Miscellaneous UI Controls | Atc.Wpf & Atc.Wpf.Theming |
39-
| Atc.Wpf.Controls.Sample | Controls for creating WPF sample apps | Atc.Wpf & Atc.Wpf.Theming |
40-
| Atc.Wpf.FontIcons | Render Svg and Img resources based on fonts | Atc.Wpf |
41-
| Atc.Wpf.Theming | Theming for Light & Dark mode for WPF base controls | Atc.Wpf |
39+
| 💟 Atc.Wpf | Base Controls, ValueConverters, Extensions etc. | Atc & Atc.Wpf.SourceGenerators |
40+
| 💟 Atc.Wpf.Controls | Miscellaneous UI Controls | Atc.Wpf & Atc.Wpf.Theming |
41+
| 💟 Atc.Wpf.Controls.Sample | Controls for creating WPF sample apps | Atc.Wpf & Atc.Wpf.Theming |
42+
| 💟 Atc.Wpf.FontIcons | Render Svg and Img resources based on fonts | Atc.Wpf |
43+
| 💟 Atc.Wpf.Theming | Theming for Light & Dark mode for WPF base controls | Atc.Wpf |
4244

43-
## Demonstration Application
45+
# 🔎 Demonstration Application
4446

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

49-
### Playground and Viewer for a Given Control or Functionality
51+
## Playground and Viewer for a Given Control or Functionality
5052

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

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

73-
## How to get started with atc-wpf
75+
# 🚀 How to get started with atc-wpf
7476

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

7779
```xml
7880
<ItemGroup>
79-
<PackageReference Include="Atc.Wpf" Version="2.0.178" />
80-
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.178" />
81-
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.178" />
82-
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.178" />
81+
<PackageReference Include="Atc.Wpf" Version="latest" />
82+
<PackageReference Include="Atc.Wpf.Controls" Version="latest" />
83+
<PackageReference Include="Atc.Wpf.FontIcons" Version="latest" />
84+
<PackageReference Include="Atc.Wpf.Theming" Version="latest" />
8385
</ItemGroup>
8486
```
8587

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

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

108-
## Readme's for each NuGet Package area
110+
## WPF with MVVM Easily Separate UI and Business Logic
111+
112+
With the `Atc.Wpf`, package, it is very easy to get startet with the nice `MVVM pattern`
113+
114+
Please read more here:
115+
116+
- [MVVM framework](docs/Mvvm/@Readme.md)
117+
- [Observerble properties](docs/Mvvm/@Readme.md)
118+
- [RelayCommands](docs/Mvvm/@Readme.md)
119+
120+
# 📝 Readme's for each NuGet Package area
109121

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

113-
### Atc.Wpf
125+
## 💟 Atc.Wpf
114126

115-
#### Controls
127+
### Controls
116128

117-
- [GridEx](src/Atc.Wpf/Controls/Layouts/GridEx_Readme.md)
118-
- [StaggeredPanel](src/Atc.Wpf/Controls/Layouts/StaggeredPanel_Readme.md)
119-
- [UniformSpacingPanel](src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel_Readme.md)
120-
- [SvgImage](src/Atc.Wpf/Controls/Media/SvgImage_Readme.md)
121-
- Control Helpers
129+
- Layouts
130+
- [GridEx](src/Atc.Wpf/Controls/Layouts/GridEx_Readme.md)
131+
- [StaggeredPanel](src/Atc.Wpf/Controls/Layouts/StaggeredPanel_Readme.md)
132+
- [UniformSpacingPanel](src/Atc.Wpf/Controls/Layouts/UniformSpacingPanel_Readme.md)
133+
- Media
134+
- [SvgImage](src/Atc.Wpf/Controls/Media/SvgImage_Readme.md)
135+
- Helpers
122136
- [PanelHelper](src/Atc.Wpf/Helpers/PanelHelper_Readme.md)
123137

124-
#### Misc
138+
### Misc
125139

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

133-
### Atc.Wpf.Controls
145+
## 💟 Atc.Wpf.Controls
134146

135-
#### Controls
147+
### Controls
136148

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

139-
#### Misc
151+
### Misc
140152

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

143-
### Atc.Wpf.FontIcons
155+
## 💟 Atc.Wpf.FontIcons
144156

145-
#### Misc
157+
### Misc
146158

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

149-
### Atc.Wpf.Theming
161+
## 💟 Atc.Wpf.Theming
150162

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

153-
### Source Generators
165+
# ⚙️ Source Generators
154166

155-
In MVVM, certain attributes help automate boilerplate code using source generators.
167+
In for WPF, certain attributes help automate boilerplate code using source generators.
156168

157-
Example for ViewModel classes
169+
Read more about here:
158170

159-
![MVVM Source Generation](docs/images/mvvm-source-generated.png)
160-
161-
For more details, see the [MVVM](src/Atc.Wpf/Mvvm/@Readme.md) section.
171+
- [SourceGenerators for AttachedProperties](docs/SourceGenerators/AttachedProperty.md)
172+
- [SourceGenerators for DependencyProperties](docs/SourceGenerators/DependencyProperty.md)
173+
- [SourceGenerators for ViewModel](docs/SourceGenerators/ViewModel.md)
162174

163-
### DependencyProperty
175+
Example for ViewModel classes
164176

165-
### Human made Code for complex property
166-
167-
```csharp
168-
[DependencyProperty<bool>("IsRunning")]
169-
public partial class MyControl : UserControl
170-
{
171-
}
172-
```
173-
174-
### Human made Code for simple property
175-
176-
```csharp
177-
[DependencyProperty<bool>("IsRunning"]
178-
public partial class MyControl : UserControl
179-
{
180-
}
181-
```
182-
183-
### Generated Code for simple property
184-
185-
```csharp
186-
public partial class MyControl
187-
{
188-
public static readonly DependencyProperty IsRunningProperty = DependencyProperty.Register(
189-
nameof(IsRunning),
190-
typeof(bool),
191-
typeof(MyControl),
192-
new FrameworkPropertyMetadata(defaultValue: BooleanBoxes.TrueBox);
193-
194-
public bool IsRunning
195-
{
196-
get => (bool)GetValue(IsRunningProperty);
197-
set => SetValue(IsRunningProperty, value);
198-
}
199-
}
200-
```
177+
![MVVM Source Generation](docs/images/mvvm-source-generated.png)
201178

202-
### Generated Code for complex property
203-
204-
```csharp
205-
public partial class MyControl
206-
{
207-
public static readonly DependencyProperty IsRunningProperty = DependencyProperty.Register(
208-
nameof(IsRunning),
209-
typeof(bool),
210-
typeof(MyControl),
211-
new FrameworkPropertyMetadata(
212-
defaultValue: BooleanBoxes.TrueBox,
213-
propertyChangedCallback: PropertyChangedCallback,
214-
coerceValueCallback: CoerceValueCallback,
215-
flags: FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
216-
defaultUpdateSourceTrigger: UpdateSourceTrigger.Default,
217-
isAnimationProhibited: true));
218-
219-
public bool IsRunning
220-
{
221-
get => (bool)GetValue(IsRunningProperty);
222-
set => SetValue(IsRunningProperty, value);
223-
}
224-
}
225-
```
179+
For more details, see the [MVVM](docs/Mvvm/@Readme.md) section.
226180

227-
## How to contribute
181+
# How to contribute
228182

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

Diff for: docs/Mvvm/@Readme.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# MVVM in WPF
2+
3+
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.
4+
5+
The **Atc.Wpf** library provides a robust foundation for implementing MVVM effectively, reducing boilerplate code and simplifying development.
6+
7+
## Features
8+
9+
The `Atc.Wpf` library offers a variety of base classes and utilities to streamline MVVM implementation:
10+
11+
| Component | Description |
12+
|---------------------------|--------------------------------------------------------------------------------|
13+
| `ViewModelBase` | A base class for ViewModels. |
14+
| `MainWindowViewModelBase` | A base class for the main window ViewModel. |
15+
| `ViewModelDialogBase` | A base class for dialog ViewModels. |
16+
| `ObservableObject` | A base class for observable objects implementing `INotifyPropertyChanged`. |
17+
| `RelayCommand` | A command supporting `CanExecute`. |
18+
| `RelayCommand<T>` | A command with a generic parameter and `CanExecute`. |
19+
| `RelayCommandAsync` | An asynchronous command supporting `CanExecute`. |
20+
| `RelayCommandAsync<T>` | An asynchronous command with a generic parameter and `CanExecute`. |
21+
22+
For detailed information about commands, refer to the [RelayCommand documentation](../SourceGenerators/ViewModel.md).
23+
24+
---
25+
26+
### Getting started using `ViewModelBase`
27+
28+
Below is a simple example demonstrating how to create a ViewModel using `ViewModelBase`:
29+
30+
```csharp
31+
public class MyViewModel : ViewModelBase
32+
{
33+
private string myProperty;
34+
35+
public string MyProperty
36+
{
37+
get => myProperty;
38+
set
39+
{
40+
if (myProperty == value)
41+
{
42+
return;
43+
}
44+
45+
myProperty = value;
46+
RaisePropertyChanged();
47+
}
48+
}
49+
}
50+
```

0 commit comments

Comments
 (0)