WpfCoreTools 1.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package WpfCoreTools --version 1.5.0
NuGet\Install-Package WpfCoreTools -Version 1.5.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="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WpfCoreTools --version 1.5.0
#r "nuget: WpfCoreTools, 1.5.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=1.5.0

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

icon

WpfCoreTools

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

release nuget release_date downloads license

Dependencies

net5 net6 coretools

Content

Content of the package:

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.

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.

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.

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.

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.

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.

IDialog

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

T? GetResult()

Gets the result.

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.

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.

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.

System.Windows.Media.Color ToMediaColor()

Converts the System.Drawing.Color to a System.Windows.Media.Color.

System.Drawing.Color ToDrawingColor()

Converts the System.Windows.Media.Color to a System.Drawing.Color.

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.

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.

PointExtensions

This static class provides a set of Point extensions:

System.Windows.Point ToWindowsPoint()

Converts the System.Drawing.Point to a System.Windows.Point.

System.Drawing.Point ToDrawingPoint()

Converts the System.Windows.Point to a System.Drawing.Point.

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.

System.Windows.Size ToWindowsSize()

Converts the System.Drawing.Size to a System.Windows.Size.

System.Drawing.Size ToDrawingSize()

Converts the System.Windows.Size to a System.Drawing.Size.

Size UniformSize(double dim)

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

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.

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.

License

Copyright (C) 2021-2022 devpelux (Salvatore Peluso)
Licensed under MIT license.

mit

Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0-windows was computed.  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.

Version Downloads Last updated
2.0.0 137 11/6/2023
1.6.0 334 2/16/2023
1.5.0 757 5/20/2022
1.4.0 423 5/13/2022
1.3.0.3 428 4/28/2022
1.2.0 421 4/22/2022
1.1.1 426 4/22/2022
1.1.0 461 1/7/2022
1.0.0 471 12/30/2021

Reimplemented DialogWindow and IDialog with generics instead of objects, avoiding boxing and unboxing values.
Updated CoreTools to 1.2.0.