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/maintenance #143

Merged
merged 7 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Atc.Wpf.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<s:Boolean x:Key="/Default/CodeEditing/SuppressUninitializedWarningFix/Enabled/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=adorner/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=adorners/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=broadcasted/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=casted/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Checkmark/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=children_0027s/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<PackageReference Include="Meziantou.Analyzer" Version="2.0.188" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.6.0.109712" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.7.0.110445" PrivateAssets="All" />
</ItemGroup>

</Project>
36 changes: 31 additions & 5 deletions docs/SourceGenerators/ViewModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,36 @@ private string name;
// Generates a property named "MyName" and notifies FullName and Age
[ObservableProperty(nameof(MyName), DependentProperties = [nameof(FullName), nameof(Age)])]
private string name;

// Generates a property named "Name" and broadcast message
[ObservableProperty(BroadcastOnChange = true)]
private string name;
```

### 🔔 Notifying Other Properties

```csharp
// Generates a property named "Name" and notifies FullName and Age
// Notifies multiple propertries as FullName and Age
[ObservableProperty(DependentProperties = [nameof(FullName), nameof(Age)])]

// Notifies the property "Email"
[NotifyPropertyChangedFor(nameof(Email))]

// Notifies multiple properties
// Notifies multiple propertries as FullName and Age
[NotifyPropertyChangedFor(nameof(FullName), nameof(Age))]
```

**Note:**

- `NotifyPropertyChangedFor` ensures that when the annotated property changes, specified dependent properties also get notified.

### 🔔 Notifying Other ViewModels or Controls

```csharp
// Notifies by broadcast a message by type PropertyChangedMessage
[ObservableProperty(BroadcastOnChange = true)]
```

### 🔮 Callbacks

```csharp
Expand Down Expand Up @@ -123,6 +134,7 @@ The `RelayCommand` attribute generates `IRelayCommand` properties, eliminating m

- `CommandName` for customization.
- `CanExecute` a property or method that return `bool` to specified to control when the command is executable.
- `InvertCanExecute` if the property `CanExecute` is defined, this property will invert the outcome from the property or method `CanExecute` relays on.
- `ParameterValue` or `ParameterValues` for 1 or many parameter values.

### 🛠 Quick Start Tips for RelayCommands
Expand All @@ -147,6 +159,10 @@ public void Save(string text);
// Generates a RelayCommand with CanExecute function
[RelayCommand(CanExecute = nameof(CanSave))]
public void Save();

// Generates a RelayCommand with CanExecute function
[RelayCommand(CanExecute = nameof(IsConnected), InvertCanExecute = true)]
public void Connect();
```

**Note:**
Expand Down Expand Up @@ -188,6 +204,10 @@ public Task Save();
// Generates an asynchronous RelayCommand with async keyword and CanExecute function
[RelayCommand(CanExecute = nameof(CanSave))]
public async Task Save();

// Generates an asynchronous RelayCommand async keyword and CanExecute function
[RelayCommand(CanExecute = nameof(IsConnected), InvertCanExecute = true)]
public async Task Connect();
```

### 🔁 Multi-Parameter Commands
Expand Down Expand Up @@ -364,7 +384,7 @@ public partial class TestViewModel
```csharp
public partial class PersonViewModel : ViewModelBase
{
[ObservableProperty]
[ObservableProperty(BroadcastOnChange = true)]
[NotifyPropertyChangedFor(nameof(FullName))]
[Required]
[MinLength(2)]
Expand All @@ -387,7 +407,11 @@ public partial class PersonViewModel : ViewModelBase

public string FullName => $"{FirstName} {LastName}";

[RelayCommand]
public bool IsConnected { get; set; }

[RelayCommand(
CanExecute = nameof(IsConnected),
InvertCanExecute = true)]
public void ShowData()
{
// TODO: Implement ShowData - it could be a dialog box
Expand Down Expand Up @@ -417,7 +441,7 @@ public partial class PersonViewModel : ViewModelBase
```csharp
public partial class PersonViewModel
{
public IRelayCommand ShowDataCommand => new RelayCommand(ShowData);
public IRelayCommand ShowDataCommand => new RelayCommand(ShowData, () => !IsConnected);

public IRelayCommand SaveHandlerCommand => new RelayCommand(SaveHandler, CanSaveHandler);

Expand All @@ -431,9 +455,11 @@ public partial class PersonViewModel
return;
}

var oldValue = firstName;
firstName = value;
RaisePropertyChanged(nameof(FirstName));
RaisePropertyChanged(nameof(FullName));
Broadcast(nameof(FirstName), oldValue, value);
}
}

Expand Down
37 changes: 32 additions & 5 deletions sample/Atc.Wpf.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// ReSharper disable once UnusedParameter.Local
namespace Atc.Wpf.Sample;

/// <summary>
/// Interaction logic for App.
/// </summary>
public partial class App
{
private readonly IHost host;
private IConfiguration? configuration;

public App()
{
EnsureAppSettingsInCommonDataDirectory();

host = Host.CreateDefaultBuilder()
.ConfigureLogging(logging =>
{
Expand All @@ -21,8 +20,12 @@ public App()
.ConfigureAppConfiguration((_, configurationBuilder) =>
{
configuration = configurationBuilder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(AtcFileNameConstants.AppSettings, optional: false, reloadOnChange: true)
.AddJsonFile(AtcFileNameConstants.AppSettingsCustom, optional: true, reloadOnChange: true)
.AddJsonFile(
Path.Combine(
AppConstants.DataDirectory.FullName,
AtcFileNameConstants.AppSettings),
optional: false,
reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
})
Expand Down Expand Up @@ -147,4 +150,28 @@ await host

host.Dispose();
}

private static void EnsureAppSettingsInCommonDataDirectory()
{
var dataDirectoryFile = AppConstants.DataDirectory.CombineFileInfo(AtcFileNameConstants.AppSettings);
if (dataDirectoryFile.Exists)
{
return;
}

if (!Directory.Exists(AppConstants.DataDirectory.FullName))
{
Directory.CreateDirectory(AppConstants.DataDirectory.FullName);
}

var deployedFile = new FileInfo(
Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
AtcFileNameConstants.AppSettings));

File.Copy(
deployedFile.FullName,
dataDirectoryFile.FullName,
overwrite: true);
}
}
16 changes: 16 additions & 0 deletions sample/Atc.Wpf.Sample/AppConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Atc.Wpf.Sample;

public static class AppConstants
{
public const string CompanyName = "ATC";

public const string AppIdentifier = "Atc.Wpf.Sample";

public const string AppDisplayName = "Atc Wpf Sample";

public static DirectoryInfo DataDirectory => new(
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
CompanyName,
AppIdentifier));
}
14 changes: 5 additions & 9 deletions sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</ItemGroup>

<ItemGroup>
<None Remove="appsettings.custom.json" />
<None Remove="appsettings.json" />
<None Remove="Assets\a.svg" />
<None Remove="Assets\atc.png" />
Expand All @@ -28,9 +27,6 @@
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.custom.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -53,11 +49,11 @@

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.552" />
<PackageReference Include="ControlzEx" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.2" />
<PackageReference Include="ControlzEx" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions sample/Atc.Wpf.Sample/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
global using System;
global using System.Collections;
global using System.Collections.Generic;
global using System.Collections.ObjectModel;
global using System.Collections.Specialized;
global using System.ComponentModel;
Expand All @@ -7,6 +9,7 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.IO;
global using System.Linq;
global using System.Runtime.CompilerServices;
global using System.Text;
global using System.Text.Json;
Expand All @@ -28,6 +31,7 @@
global using Atc.Wpf.Controls.LabelControls.Extractors;
global using Atc.Wpf.Controls.LabelControls.Writers;
global using Atc.Wpf.Controls.Media;
global using Atc.Wpf.Controls.Monitoring;
global using Atc.Wpf.Controls.Notifications;
global using Atc.Wpf.Controls.Options;
global using Atc.Wpf.Controls.Sample;
Expand All @@ -44,7 +48,9 @@
global using Atc.Wpf.Theming.Helpers;
global using Atc.Wpf.Translation;
global using Atc.Wpf.ValueConverters;

global using ControlzEx.Theming;

global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
Expand Down
3 changes: 0 additions & 3 deletions sample/Atc.Wpf.Sample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample;

/// <summary>
/// Interaction logic for MainWindow.
/// </summary>
public partial class MainWindow
{
private IMainWindowViewModel GetViewModel() => (IMainWindowViewModel)DataContext!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Commands;

/// <summary>
/// Interaction logic for RelayCommandAsyncView.
/// </summary>
public partial class RelayCommandAsyncView
{
public RelayCommandAsyncView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Commands;

/// <summary>
/// Interaction logic for RelayCommandView.
/// </summary>
public partial class RelayCommandView
{
public RelayCommandView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for AutoGridView.
/// </summary>
public partial class AutoGridView
{
public AutoGridView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for GridExView.
/// </summary>
public partial class GridExView
{
public GridExView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for GridLinesView.
/// </summary>
public partial class GridLinesView
{
public GridLinesView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for PanelHelperView.
/// </summary>
public partial class PanelHelperView
{
public PanelHelperView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for ReversibleStackPanelView.
/// </summary>
public partial class ReversibleStackPanelView
{
public ReversibleStackPanelView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for StaggeredPanelView.
/// </summary>
public partial class StaggeredPanelView
{
public StaggeredPanelView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Layouts;

/// <summary>
/// Interaction logic for UniformSpacingPanelView.
/// </summary>
public partial class UniformSpacingPanelView
{
public UniformSpacingPanelView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Media;

/// <summary>
/// Interaction logic for AutoGreyableImageView.
/// </summary>
public partial class AutoGreyableImageView
{
public AutoGreyableImageView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Media;

/// <summary>
/// Interaction logic for SvgImageListView.
/// </summary>
public partial class SvgImageListView
{
public SvgImageListView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
namespace Atc.Wpf.Sample.SamplesWpf.Controls.Media;

/// <summary>
/// Interaction logic for SvgImageView.
/// </summary>
public partial class SvgImageView
{
public SvgImageView()
Expand Down
Loading
Loading