BionicUtilities.Net
1.4.1
BionicCode.Utilities.Net.Framework.Wpf
Additional DetailsBreaking change: the library has been moved to a new package and namespace: "BionicCode.Utilities.Net.Framework.Wpf" (and the dependency to "BionicCode.Utilities.Net.Standard"). Please install the "BionicCode.Utilities.Net.Framework.Wpf" package from now on. Remarks: only the namespaces have changed. Class names remain the same (except the class 'BaseViewModel` has been renamed to 'ViewModel' and 'IBaseViewModel' to 'IViewModel'. The 'BaseViewModel' class and the 'IBaseViewModel' interface are still available for backward compatibility, but have been marked as deprecated). For the .NET Core version please install the new "BionicCode.Utilities.Net.Core.Wpf" package.
dotnet add package BionicUtilities.Net --version 1.4.1
NuGet\Install-Package BionicUtilities.Net -Version 1.4.1
<PackageReference Include="BionicUtilities.Net" Version="1.4.1" />
<PackageVersion Include="BionicUtilities.Net" Version="1.4.1" />
<PackageReference Include="BionicUtilities.Net" />
paket add BionicUtilities.Net --version 1.4.1
#r "nuget: BionicUtilities.Net, 1.4.1"
#:package BionicUtilities.Net@1.4.1
#addin nuget:?package=BionicUtilities.Net&version=1.4.1
#tool nuget:?package=BionicUtilities.Net&version=1.4.1
BionicUtilities.Net
Reusable utility and class library for WPF.
NuGet package
Class Reference
GitHub
Contains (snippet - full read me here)
(Click class link to load example)
BaseViewModel- Encapsulation of basic view model behavior and features.AsyncRelayCommand<T>- AsynchronousICommandimplementation.- Extension Methods for WPF e.g.
TryFindVisualParentElement<TParent> : boolTryFindVisualParentElementByName : boolTryFindVisualChildElement<TChild> : boolTryFindVisualChildElementByName : boolFindVisualChildElements<TChildren> : IEnumerable<TChildren>ICollection.AddRange<T>
- EventArgs
ValueChangedEventArgs<T>- EventArgs that exposesOldValueandNewValuepropertiesValueEventArgs<T>- EventArg thar holds a value T
- ValueConverters
BoolToStringConverterBooleanMultiValueConverterFilePathTruncateConverterInvertValueConverter
- Collections
ObservablePropertyChangedCollection<T>
- MarkupExtensions
PrimitiveTypeExtension
Profiler- Profiling APIAppSettingsConnector- A default API to the AppSettings that provides strongly typed reading and writing (e.g.boo,int,double,string) of key-value pair valuesMruManager- Most Recently Used (MRU) file manager. An API that maintains an MRU table stored in the Application Settings file.EventAggregator- Implememtation of the EventAggregator pattern that supports dynamic aggregation of different typed event sources- Easy to use
DialogAttached Behavior and infrastructure to allow MVVM friendly dialog handling from the view models in a fire-and-forget manner. To display dialogs implementIDialogViewModelclasses and create aDataTemplatefor each implementation. TheDataTemplateis the rendered in a nativeWindow. Addition attached properties allow for styling of the dialogWindowor to assign an optionalDataTemplateSelector. The attached behavior will handle showing and closing of the dialog.
BaseViewModel
- Implements and encapsulates
INotifyPropertyChangedandINotifyDataErrorInfo. - Allows to control whether invalid data is set on a property or neglected until validation passes by setting the default parameter
isRejectInvalidValueEnabledofTrySetValue()totrue(neglects invalid values by default). - Also allows to control whether to throw an exception on validation error or not (silent) by setting the default parameter
isThrowExceptionOnValidationErrorEnabledofTrySetValue()totrue(is silent by default). - Additionally exposes a
PropertyValueChangedevent which is raised in tandem withINotifyPropertyChanged.PropertyChangedbut additionally carries old value and new value as event args.
Example with validation
private string name;
public string Name
{
get => this.name;
set
{
if (TrySetValue(
value,
(stringValue) =>
{
var messages = new List<string>() {"Name must start with an underscore"};
return (stringValue.StartsWith("_"), messages);
},
ref this.name))
{
DoSomething(this.name);
}
}
}
Example without validation
private string name;
public string Name
{
get => this.name;
set
{
if (TrySetValue(value, ref this.name))
{
DoSomething(this.name);
}
}
}
AsyncRelayComand<T>
Reusable generic command class that encapsulates ICommand and allows asynchronous execution.
When used with a Binding the command will execute asynchronously when an awaitable execute handler is assigned to the command.
Example
// ICommand property
public IAsyncRelayCommand<string> StringAsyncCommand => new AsyncRelayCommand<string>(ProcessStringAsync);
// Execute asynchronously
await StringAsyncCommand.ExecuteAsync("String value");
// Execute synchronously
StringAsyncCommand.Execute("String value");
Profiler
Static helper methods to measure performance e.g. the execution time of a code portion.
Example
// Specify a custom output
Profiler.LogPrinter = (timeSpan) => PrintToFile(timeSpan);
// Measure the average execution time of a specified number of iterations.
TimeSpan elapsedTime = Profiler.LogAverageTime(() => ReadFromDatabase(), 1000);
// Measure the execution times of a specified number of iterations.
List<TimeSpan> elapsedTime = Profiler.LogTimes(() => ReadFromDatabase(), 1000);
// Measure the execution time.
TimeSpan elapsedTime = Profiler.LogTime(() => ReadFromDatabase());
ValueChangedEventArgs<T>
Generic EventArgs implementation that provides value change information like OldValue and NewValue.
Example
// Specify a named ValueTuple as event argument
event EventHandler<ValueChangedEventArgs<(bool HasError, string Message)>> Completed;
protected virtual void RaiseCompleted((bool HasError, string Message) oldValue, (bool HasError, string Message) newValue)
{
this.Completed?.Invoke(this, new ValueChangedEventArgs<(bool HasError, string Message)>(oldValue, newValue));
}
private void OnCompleted(object sender, ValueChangedEventArgs<(bool HasError, string Message)> e)
{
(bool HasError, string Message) newValue = e.NewValue;
if (newValue.HasError)
{
this.TaskCompletionSource.TrySetException(new InvalidOperationException(newValue.Message));
}
this.TaskCompletionSource.TrySetResult(true);
}
AppSettingsConnector
A static default API to the AppSettings that provides strongly typed reading and writing (e.g. boo, int, double, string) of key-value pair values.
Example
// Write the Most Recently Used file count to the AppSettings file
AppSettingsConnector.WriteInt("mruCount", 10);
// If key exists read the Most Recently Used file count from the AppSettings file
if (TryReadInt("mruCount", out int mruCount))
{
this.MruCount = mruCount;
}
GitHub (full read me here)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 is compatible. net481 was computed. |
-
- JetBrains.Annotations (>= 2019.1.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.4.1 | 1,660 | 12/4/2019 | |
| 1.2.1 | 1,445 | 10/18/2019 | |
| 1.2.0 | 1,419 | 10/13/2019 | |
| 1.1.13 | 1,419 | 10/12/2019 | |
| 1.1.12 | 1,450 | 10/3/2019 | |
| 1.1.11 | 1,474 | 10/3/2019 | |
| 1.1.10 | 1,402 | 10/3/2019 | |
| 1.1.9 | 1,451 | 10/3/2019 | |
| 1.1.8 | 1,466 | 10/3/2019 | |
| 1.1.7 | 1,438 | 10/3/2019 | |
| 1.1.6 | 1,404 | 10/3/2019 | |
| 1.1.5 | 1,465 | 10/1/2019 | |
| 1.1.4 | 1,452 | 10/1/2019 | |
| 1.1.0 | 1,436 | 9/29/2019 |
- Fixed AsyncRelayCommand when using no param overload of CanExecute()
- Added dynamic multitype EventAggregator
- Added PropertyValueChanged event to BaseViewModel
- Added MVVM conform display dialog infrastructure
---------------------------------------------------------
For bug reports or feature requests please visit the project home on GutHub (follow the "Project Site" link on the right) and then open an issue (open the "issue" tab, click "New Issue" and select the appropriate template) or send a mail to BionicCode@outlook.com. Thank you very much.