WpfCoreTools 2.0.0

dotnet add package WpfCoreTools --version 2.0.0                
NuGet\Install-Package WpfCoreTools -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WpfCoreTools" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WpfCoreTools --version 2.0.0                
#r "nuget: WpfCoreTools, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WpfCoreTools as a Cake Addin
#addin nuget:?package=WpfCoreTools&version=2.0.0

// Install WpfCoreTools as a Cake Tool
#tool nuget:?package=WpfCoreTools&version=2.0.0                

WpfCoreTools

Lightweight package with some utilities for .NET Core wpf applications.

Dependencies

net6 net7 drawing_common

Content

Content of the package:

BoolValues

This class provides boxed values for bool values, and some functions to box and unbox bool values:

object True = true

Boxed value for true.

object False = false

Boxed value for false.

object Box(bool value)

Boxes a bool value.
Parameters:
value: Value to box.

bool Unbox(object value)

Unboxes a bool value.
Parameters:
value: Value to unbox.

ClipConverter

This class is a converter that clips elements that are out of a control, and contains the following functions:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)

Calculates and returns a clip with the specified parameters.
Parameters:
values: Array containing some properties of the control to clip. (Width, Height, CornerRadius, BorderThickness)
targetType: Unused.
parameter: Unused.
culture: Unused.

object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

Unsupported.

DelegateCommand

Defines a command with delegated Execute and CanExecute.

DelegateCommand(Action<object?> execute)

Initializes a new instance of DelegateCommand that is always executable.
Parameters:
execute: Action called when the command is invoked.

DelegateCommand(Action<object?> execute, Predicate<object?>? canExecute)

Initializes a new instance of DelegateCommand specifying a predicate that determines if the command can be executed or not.
Parameters:
execute: Action called when the command is invoked.
canExecute: Predicate called when it is to be determined whether the command can be executed or not.

Action<object?> ExecuteDelegate { get; }

Gets the Execute delegate.

Predicate<object?>? CanExecuteDelegate { get; }

Gets the CanExecute delegate.

DialogWindow

This class is a decorator that incapsulates a Window to be displayed as dialog and, in the end, returns a result.

DialogWindow(Window window)

Initializes a new instance of DialogWindow.
Parameters:
window: The Window to be shown as dialog.

T? Show()

Displays the dialog and, in the end, returns a result.

GDIUtils

This static class contains the following functions:

Color GetPixelColor(Point pos, [bool takeScreenshotWhenPossible = false])

Returns the color of the pixel at a specified position.
Parameters:
pos: Position of the pixel from to get the color.
takeScreenshotWhenPossible: Take a screenshot when possible to get the pixel color (this may be slower and is supported only in Windows).

Color GetPixelColorAtCursorPos([bool takeScreenshotWhenPossible = false])

Returns the color of the pixel at the current cursor position on display.
Parameters:
takeScreenshotWhenPossible: Take a screenshot when possible to get the pixel color (this may be slower and is supported only in Windows).

BitmapSource? CaptureScreenshot(Point pos, Size size)

Captures a screenshot from a specified position, with a specified size (returns null if an error occurred).
Parameters:
pos: Top-left corner of the screenshot.
size: Size of the screenshot.

BitmapSource? CaptureScreenshotAtCursorPos(Size size, Size offset)

Captures a screenshot from the current cursor position on display, with a specified size, and offset (returns null if an error occurred).
Parameters:
size: Size of the screenshot.
offset: Offset of the screenshot.

BitmapSource? CaptureScreenshotAtCursorPos(Size size)

Captures a screenshot from the current cursor position on display, with a specified size (returns null if an error occurred).
Parameters:
size: Size of the screenshot.

GraphicUtils

This static class contains the following functions:

Point GetCursorPos()

Returns the current cursor position on display.

BitmapImage LoadBitmapImageFromUri(string uri)

Loads a BitmapImage from the specified uri string.
Parameters:
uri: Uri string of the image to load.

IDialog

This interface defines an object that can return a result, and contains the following functions:

T? GetResult()

Gets the result.

MathUtils

This static class provides "fuzzy" comparison functionality for doubles and some common double-based classes and structs:

double DOUBLE_EPSILON = 2.2204460492503131e-016

The smallest double such that 1.0 + DOUBLE_EPSILON != 1.0.

bool AreClose(double value1, double value2)

Returns whether or not two double are close.
Parameters:
value1: The first double to compare.
value2: The first double to compare.

bool LessThan(double value1, double value2)

Returns whether or not the first double is less than the second double.
Parameters:
value1: The first double to compare.
value2: The first double to compare.

bool GreaterThan(double value1, double value2)

Returns whether or not the first double is greater than the second double.
Parameters:
value1: The first double to compare.
value2: The first double to compare.

bool LessThanOrClose(double value1, double value2)

Returns whether or not the first double is less than or close to the second double.
Parameters:
value1: The first double to compare.
value2: The first double to compare.

bool GreaterThanOrClose(double value1, double value2)

Returns whether or not the first double is greater than or close to the second double.
Parameters:
value1: The first double to compare.
value2: The first double to compare.

bool IsOne(double value)

Returns whether or not the double is close to 1.
Parameters:
value: The double to compare to 1.

bool IsZero(double value)

Returns whether or not the double is close to 0.
Parameters:
value: The double to compare to 0.

bool IsBetweenZeroAndOne(double value)

Returns whether or not the double is between 0 and 1.
Parameters:
value: The double to check.

bool AreClose(Point point1, Point point2)

Compares two Point for fuzzy equality.
Parameters:
point1: The first Point to compare.
point2: The second Point to compare.

bool AreClose(Size size1, Size size2)

Compares two Size for fuzzy equality.
Parameters:
size1: The first Size to compare.
size2: The second Size to compare.

bool AreClose(Vector vector1, Vector vector2)

Compares two Vector for fuzzy equality.
Parameters:
vector1: The first Vector to compare.
vector2: The second Vector to compare.

bool AreClose(Rect rect1, Rect rect2)

Compares two Rect for fuzzy equality.
Parameters:
rect1: The first Rect to compare.
rect2: The second Rect to compare.

SystemUtils

This static class contains the following functions:

Window? GetActiveWindow()

Returns the current active window (returns null if there is no active window).

FileInfo GetExecutingFile()

Returns the current application executing file.

DirectoryInfo GetExecutingDirectory()

Returns the current application executing directory.

BitmapSourceExtensions

This static class provides a set of BitmapSource extensions:

Bitmap? ToBitmap()

Converts the BitmapSource to a Bitmap.

BitmapSource? ToBitmapSource()

Converts the Bitmap to a BitmapSource.

ColorExtensions

This static class provides a set of Color extensions:

Color Invert()

Inverts the color by subtracting every value R, G, B from 255.

DependencyObjectExtensions

This static class provides a set of DependencyObject extensions:

bool IsNull(DependencyProperty dependencyProperty)

Checks if the DependencyProperty is null.
Parameters:
dependencyProperty: DependencyProperty to check if is null.

bool IsNotNull(DependencyProperty dependencyProperty)

Checks if the DependencyProperty is not null.
Parameters:
dependencyProperty: DependencyProperty to check if is not null.

RectExtensions

This static class provides a set of Rect extensions:

bool HasNaN()

Returns true if the Rect has one of his parameters setted to NaN.

bool HasArea()

Returns whether or not the Rect has an area greater than 0.
This is equal to check if width and height are greater than 0.

Rect Inflate(Thickness thickness)

Expands or shrinks the rectangle by using the specified Thickness.
Parameters:
b: Thickness to use to expand or shrink the Rect.

Rect Clone()

Returns a new Rect instance equal to the original.

SizeExtensions

This static class provides a set of Size extensions:

Size Add(Size b)

Sums a Size to the current Size.
Parameters:
b: Size to sum to the current.

Size Subtract(Size b)

Subtracts a Size from the current Size.
Parameters:
b: Size to subtract from the current.

Size UniformSize(double dim)

Initializes a new Size with uniform dimensions.
Parameters:
dim: Dimensions.

StoryboardExtensions

This static class provides a set of Storyboard extensions:

Task BeginAsync()

Applies the animations associated with this Storyboard to their targets and initiates them asyncronously.

StringExtensions

This static class provides a set of string extensions:

bool IsDouble()

Checks if the string is a double.

bool IsInt()

Checks if the string is an int.

bool IsNumeric()

Checks if the string contains only numeric chars.

string NormalizeForDouble([bool ignoreFractionalZeros = true])

Normalizes the string for the type double.
Parameters:
ignoreFractionalZeros: Ignore if there are only zeros as the fractional part to speed up the algorithm.

string NormalizeForInt()

Normalizes the string for the type int.

string Append(char c)

Appends a char at the end of the string.
Parameters:
c: char to append.

string Append(string str)

Appends a string at the end of the string.
Parameters:
str: string to append.

string Reduce(int count)

Cuts the string by removing a specified number of chars from the end of the string.
Parameters:
count: Number of chars to remove from the end of the string.

string TakeStr(int count)

Returns a string by taking only the specified number of chars from the start of the string.
Parameters:
count: Number of chars to take from the start of the string.

string ToInt(int defaultValue)

Converts the string to an int. In case of errors returns a specified default value.
Parameters:
defaultValue: The default value used in case of errors.

string ToDouble(double defaultValue)

Converts the string to a double. In case of errors returns a specified default value.
Parameters:
defaultValue: The default value used in case of errors.

T? ParseTo<T>(T? defaultValue)

Converts the string to the specific type using a TypeDescriptor converter. In case of errors returns a specified default value.
Parameters:
defaultValue: The default value used in case of errors.

ThicknessExtensions

This static class provides a set of Thickness extensions:

Thickness Add(Thickness b)

Sums a Thickness to the current Thickness.
Parameters:
b: Thickness to sum to the current.

Thickness Subtract(Thickness b)

Subtracts a Thickness from the current Thickness.
Parameters:
b: Thickness to subtract from the current.

Thickness Invert()

Inverts the Thickness by replacing every value with its negative.

Size Collapse()

Collapses the Thickness into a Size.

License

Licensed under Unlicense.

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Now this project is under public domain.