Oakrey.Applications.ControlObjects
4.1.1
dotnet add package Oakrey.Applications.ControlObjects --version 4.1.1
NuGet\Install-Package Oakrey.Applications.ControlObjects -Version 4.1.1
<PackageReference Include="Oakrey.Applications.ControlObjects" Version="4.1.1" />
<PackageVersion Include="Oakrey.Applications.ControlObjects" Version="4.1.1" />
<PackageReference Include="Oakrey.Applications.ControlObjects" />
paket add Oakrey.Applications.ControlObjects --version 4.1.1
#r "nuget: Oakrey.Applications.ControlObjects, 4.1.1"
#:package Oakrey.Applications.ControlObjects@4.1.1
#addin nuget:?package=Oakrey.Applications.ControlObjects&version=4.1.1
#tool nuget:?package=Oakrey.Applications.ControlObjects&version=4.1.1
Oakrey.Applications.ControlObjects
A .NET / WPF library that provides a hierarchy of base classes and interfaces for building interactive, validated control objects. It covers object validation, keyboard gesture binding, device communication, timer-driven and cancelable operations, observable collections with automatic JSON persistence, and supporting WPF converters.
Main features
- Property-level validation via
ValidableObjectwith per-property error messages and an aggregateIsValid/Errorssurface - Generic
SendingObject<TData>base with reactiveIObservable<TData>data stream,IObservable<Exception>error stream, and multi-key gesture support EnableObject<TData>- toggle-based enable/disable withColorandToolTipbindingsTimerObject<TData>- periodic sending driven by a configurablePeriod(TimeSpan)CancelableObject<TData>- async operation with cooperative cancellation viaCancellationToken; exposes visualColorstateISendingDevice<TData>abstraction for downstream hardware or service targets withIObservable<DeviceStatus>status streamSendingObjectCollection<TData, TSendingObject>-ObservableCollectionthat auto-saves and auto-loads its items as JSON, reacts to device status changes, and routes gesturesICollectionService<TItem>- lightweight add/remove collection interfaceGestureControlMainViewModelBase- ViewModel base for windows/pages that own multiple gesture controllers; exposes a page-switch observable- WPF
SelectionHighlightConverter<T>andSelectionHighlightConverterFactoryExtensionfor reference-equality-based selection highlighting
Architecture
classDiagram
class ValidableObject {
+bool IsValid
+string Errors
+SetValid()
+SetInvalid(errorMessage)
}
class CollectionObject {
+string Name
+string Description
}
class SendingObject~TData~ {
+IObservable~TData~ DataToSend
+IObservable~Exception~ Error
+IObservable~string~ Info
+MultiKeyGesture Gesture
+ICommand Click
}
class EnableObject~TData~ {
+bool IsEnabled
+Brush Color
+string ToolTip
}
class TimerObject~TData~ {
+TimeSpan Period
+string PeriodString
}
class CancelableObject~TData~ {
+bool IsEnabled
+Brush Color
#Task Run(CancellationToken)
}
class SendingObjectCollection~TData~ {
+IEnumerable~IGesture~ Gestures
#string ConfigFileName
#bool DisableObjectsWhenDeviceDisconnected
}
ValidableObject <|-- CollectionObject
CollectionObject <|-- SendingObject
SendingObject <|-- EnableObject
EnableObject <|-- TimerObject
SendingObject <|-- CancelableObject
SendingObjectCollection --> SendingObject : contains
SendingObjectCollection --> ISendingDevice : routes to
Key types
| Type | Description |
|---|---|
ValidableObject |
Property-level validation base; implements INotifyPropertyChanged |
CollectionObject |
Adds Name / Description; validates that Name is not empty |
SendingObject<TData> |
Reactive send + error + info streams, multi-key gesture, IDisposable |
EnableObject<TData> |
Toggle enable/disable with WPF-bindable Color and ToolTip |
TimerObject<TData> |
Periodic firing; click toggles the internal System.Timers.Timer |
CancelableObject<TData> |
Async Run with automatic CancellationTokenSource management |
ISendingDevice<TData> |
Target abstraction: SendData, PropagateInfo, PropagateException |
DeviceStatus |
Enum: Disconnected, Connected, DeviceAdded, DeviceRemoved |
SendingObjectCollection<TData,T> |
Observable collection with JSON persistence and device routing |
GestureControlMainViewModelBase |
ViewModel base for pages owning gesture controllers |
SelectionHighlightConverter<T> |
IMultiValueConverter returning Visibility based on reference equality |
Requirements
- .NET 10 or higher
- Windows 10 version 1809 (build 17763) or higher (WPF dependency)
Oakrey.UI2.0.1Oakrey.Log.Toast2.1.0System.Drawing.Common10.0.8
Installation
.NET CLI
dotnet add package Oakrey.Applications.ControlObjects
Package Manager Console
Install-Package Oakrey.Applications.ControlObjects
NuGet Package Manager
Search for Oakrey.Applications.ControlObjects in Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Configuration
SendingObjectCollection automatically persists its items to a JSON file. The file path is
resolved as:
<directory of ISettingsService.AppSettingPath>\<ConfigFileName>
Override the ConfigFileName property in each concrete collection to control the file name.
If the file does not exist on first run, an empty collection is written automatically.
Example usage
Define a concrete sending object
public class MyCommand : EnableObject<string>
{
public override void Disable() => IsEnabled = false;
}
Define a concrete collection
public class MyCommandCollection : SendingObjectCollection<string, MyCommand>
{
protected override string ConfigFileName => "myCommands.json";
public MyCommandCollection(
ISendingDevice<string> device,
IJsonService jsonService,
ISettingsService settings)
: base(device, jsonService, settings) { }
}
Subscribe to outgoing data
foreach (MyCommand cmd in collection)
{
cmd.DataToSend.Subscribe(data => device.SendData(data, cmd.Name));
cmd.Error.Subscribe(ex => logger.Error(ex.Message));
}
Implement a ViewModel with gesture support
public class MainViewModel : GestureControlMainViewModelBase
{
public MainViewModel(IEnumerable<IGestureController> controllers)
: base(controllers) { }
}
WPF selection highlight in XAML
<Border.Visibility>
<MultiBinding Converter="{local:SelectionHighlightConverterFactory}">
<Binding Path="." />
<Binding Path="DataContext.SelectedItem" RelativeSource="{RelativeSource AncestorType=Window}" />
</MultiBinding>
</Border.Visibility>
Development notes
- All
SendingObjectsubclasses implementIDisposable. Ensure collections are disposed when the owning ViewModel is torn down to release Rx subscriptions. CancelableObject.RunreturnsTask.CompletedTaskby default; override it to add async logic. Errors thrown insideRunare forwarded through theErrorobservable.GestureControlMainViewModelBaseimplementsIAutoConfigurable. OverrideLoadBasicGesturesandLoadSwitchGesturesto register application-level shortcuts.TimerObjectvalidatesPeriodStringon set; it must parse as aTimeSpanbetween 1 ms and 1 day.
Project information
- Author: Oakrey
- License: MIT
- Repository: ApplicationServices
- Package URL: NuGet - Oakrey.Applications.ControlObjects
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows10.0.17763 is compatible. |
-
net10.0-windows10.0.17763
- Oakrey.Applications.Settings (>= 5.1.5)
- Oakrey.Log.Toast (>= 2.1.0)
- Oakrey.UI (>= 2.0.1)
- System.Drawing.Common (>= 10.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.