Skip to content

Commit

Permalink
feat(models): enhance data binding and encapsulation (#42)
Browse files Browse the repository at this point in the history
Refactor properties in CustomInkCanvas, CanvasPage, Progress, and Settings classes to use public properties with [ObservableProperty] attributes. This improves data binding capabilities and encapsulation by replacing private fields with public properties. Additionally, simplify access to the StylusPlugIns collection in CustomInkCanvas.
  • Loading branch information
realybin committed Feb 19, 2025
1 parent 65a0190 commit 99fbf0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions SketchNow/Controls/CustomInkCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace SketchNow.Controls;

public class CustomInkCanvas : InkCanvas
{
CustomStylusPlugin _customStylusPlugin = new();
private readonly CustomStylusPlugin _customStylusPlugin = new();

public CustomInkCanvas()
{
this.StylusPlugIns.Add(_customStylusPlugin);
StylusPlugIns.Add(_customStylusPlugin);
}
}
9 changes: 5 additions & 4 deletions SketchNow/Models/CanvasPages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ namespace SketchNow.Models;

public partial class CanvasPage : ObservableObject
{
[ObservableProperty] private StrokeCollection _strokes = [];
[ObservableProperty]
public partial StrokeCollection Strokes { get; set; } = [];

#region Undo/Redo

/// <summary>
/// To Notify the Not ObservableProperty <see cref="_strokes"/>
/// To Notify the Not ObservableProperty <see cref="Strokes"/>
/// </summary>
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(UndoCommand), nameof(RedoCommand), nameof(ClearCommand))]
private int _counter;
public partial int Counter { get; set; }

private readonly ObservableCollection<StrokeCollection> _undoStack = [];
private readonly ObservableCollection<StrokeCollection> _redoStack = [];
Expand Down Expand Up @@ -77,7 +78,7 @@ public CanvasPage()
{
// Listen for changes in the Strokes property
Strokes.StrokesChanged += Strokes_Changed;
_undoStack.Add(CloneStrokeCollection(_strokes));
_undoStack.Add(CloneStrokeCollection(Strokes));
}

[RelayCommand(CanExecute = nameof(CanClear))]
Expand Down
8 changes: 5 additions & 3 deletions SketchNow/Models/Progress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ namespace SketchNow.Models;
public partial class Progress : ObservableObject
{
[ObservableProperty]
private int _value;
public partial int Value { get; set; }

[ObservableProperty]
private bool _isIndeterminate;
public partial bool IsIndeterminate { get; set; }

[ObservableProperty]
private bool _isVisible;
public partial bool IsVisible { get; set; }
}
8 changes: 4 additions & 4 deletions SketchNow/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace SketchNow.Models;
public partial class Settings : ObservableObject
{
[ObservableProperty]
private bool _isFitToCurve;
public partial bool IsFitToCurve { get; set; }

[ObservableProperty]
private bool _isIgnorePressure;
public partial bool IsIgnorePressure { get; set; }

[ObservableProperty]
private bool _isEraseByStroke;
public partial bool IsEraseByStroke { get; set; }

[ObservableProperty]
private Brush _selectedBackground;
public partial Brush SelectedBackground { get; set; }

public Settings()
{
Expand Down

0 comments on commit 99fbf0c

Please sign in to comment.