OneCore.Net.WPF
1.0.3
dotnet add package OneCore.Net.WPF --version 1.0.3
NuGet\Install-Package OneCore.Net.WPF -Version 1.0.3
<PackageReference Include="OneCore.Net.WPF" Version="1.0.3" />
<PackageVersion Include="OneCore.Net.WPF" Version="1.0.3" />
<PackageReference Include="OneCore.Net.WPF" />
paket add OneCore.Net.WPF --version 1.0.3
#r "nuget: OneCore.Net.WPF, 1.0.3"
#:package OneCore.Net.WPF@1.0.3
#addin nuget:?package=OneCore.Net.WPF&version=1.0.3
#tool nuget:?package=OneCore.Net.WPF&version=1.0.3
![]()
OneCore.Net.WPF Library
Overview
OneCore.Net.WPF is a utility library that offers generic WPF helpers such as clipboard access, icon reading, visual tree traversal, window hooks, and more to simplify desktop application development.
Features
- BindingAdapter: Allows to modify a binding by using another bindings to their properties.
- ControlFocus: Brings an easy possibility to focus another UI control.
- IconReader: Provides a way to read file, extension and folder icons with and without caching.
- InputWatcher: Allows to listen for global keyboard or mouse actions without the app be in focus.
- MouseHelper Provides easy check if the mouse is within a specific control by using low level pixel calculations.
- PopupHandler: Implements an auto close event for custom WPF popups.
- SystemTexts: Loads translations for the current windows language from the system.
- UIDispatcher: Gives easy access to the current UI dispatcher and allows override for unit tests.
- VisualTreeAssist: Provides an easy way to seach for UI controls by any condition in any direction in an easy way.
- WindowHooks: Gives easy ways to hook into the WinAPI queue with custom callbacks.
- WindowObserver: Gives easy ways to WinAPI events on the current window.
Getting Started
Installation:
- Install the OneCore.Net.WPF library via NuGet Package Manager:
dotnet add package OneCore.Net.WPFBindingAdapter:
- Bind a binding converter and bind a tool tip fallback value.
<TextBlock Text="{Binding Demo}" ToolTip="{Binding AnyTag}"> <Helpers:BindingAdapter.BindingExtensions> <Helpers:BindingExtensionCollection> <Helpers:BindingExtension Property="TextBlock.Text" Converter="{Binding DemoConverter}" ConverterParameter="{Binding DemoConverterParameter}" /> <Helpers:BindingExtension Property="TextBlock.ToolTip" FallbackValue="{Binding BindingFallbackValue}" /> </Helpers:BindingExtensionCollection> </Helpers:BindingAdapter.BindingExtensions> </TextBlock>ControlFocus:
- Usage.
public class MyControl : Control { protected void OnGotFocus() { ControlFocus.GiveFocus(myButton); } }IconReader:
Icon icon = new Icon { Source = IconReader.FileIcon("C:\\path\\Demo.exe", false, false) }InputWatcher:
- Watch global keyboard events.
public class DemoClass : IDisposable { private SubscribeToken _token; public void Demo() { var watcher = new InputWatcher(); _token = watcher.Observe(new KeyboardInput(Key.Delete, ModifierKeys.Control, OnDeletePress)); watcher.Start(); //watcher.Stop(); } private void OnDeletePress(KeyboardEventArgs obj) { //obj.Key //obj.KeyPressState //obj.ModifierKeys } public void Dispose() { _token.Dispose(); } }- Watch global mouse events.
public class DemoClass : IDisposable { private SubscribeToken _token; public void Demo() { var watcher = new InputWatcher(); _token = watcher.Observe(new MouseInput(MouseAction.RightDoubleClick, OnRightDoubleClick)); watcher.Start(); //watcher.Stop(); } private void OnRightDoubleClick(MouseEventArgs obj) { //obj.Modifiers } public void Dispose() { _token.Dispose(); } }MouseHelper
- Check if the mouse is within a control.
protected override void OnPreviewQueryContinueDrag(QueryContinueDragEventArgs e) { if (_dropPreviewAdorner == null) return; if (!MouseHelper.IsMouseInside(this)) RemovePreviews(); }PopupHandler:
- Auto close a custom popup.
public class Control : ContentControl { private PopupHandler _popupHandler; public override void OnApplyTemplate() { var popup = GetTemplateChild("PART_Popup") as Popup; if (popup == null) return; _popupHandler = new PopupHandler(); _popupHandler.AutoClose(popup, OnPopupClosed); } private void OnPopupClosed() { } }SystemTexts:
- Load the translation for the "Cancel" button from windows.
var cancelLabel = SystemTexts.GetString(SystemTexts.CANCEL_CAPTION);UIDispatcher:
- Use the UI dispatcher and override on unit tests.
public void ViewModel : ObservableObject { private string _name; public string Name { get => _name; set => NotifyAndSetIfChanged(ref _name, value); } public void Update(string name) { UIDispatcher.Current.Invoke(() => Name = name); } }[TestFixture] public class ViewModelTests { private ViewModel _target; [SetUp] public void Setup() { UIDispatcher.Override(Dispatcher.CurrentDispatcher); _target = new ViewModel(); } [Test] public void Update_Called_SetsTheProperty() { _target.Update("Peter"); Assert.That(_target.Name, Is.EqualTo("Peter")); } }VisualTreeAssist:
- Find the first child button.
var childButton = VisualTreeAssist.FindChild<Button>(this);- Find a child text box with a name.
var namedChildTextBox = VisualTreeAssist.FindNamedChild<TextBox>(this, "PART_TextBox");- Find parent user control but stop at the current window.
var firstUserControlInWindow = VisualTreeAssist.GetParentsUntil<UserControl, Window>(this);WindowHooks:
- Hook in to global keyboard events
public void HookIn() { var windowKeyboardHooks = new WindowHooks(); _windowKeyboardHooks.HookIn(process, WH.KEYBOARD_LL, KeyboardEventReceived); } private void KeyboardEventReceived(int code, IntPtr wParam, IntPtr lParam) { } public void HookOut() { _windowKeyboardHooks.HookOut(); }WindowObserver:
- Do something if user double clicked the window title bar.
public partial class MainView { public MainView() { InitializeComponent(); var observer = new WindowObserver(this); observer.AddCallback(OnEventHappened); } private void OnEventHappened(NotifyEventArgs e) { if (e.MessageId == OneCore.Net.WinAPI.Data.WM.NCLBUTTONDBLCLK) { // User double clicked in the non client area (title bar most likely) } } }public partial class MainView { public MainView() { InitializeComponent(); var observer = new WindowObserver(this); observer.AddCallbackFor(OneCore.Net.WinAPI.Data.WM.NCLBUTTONDBLCLK, OnEventHappened); } private void OnEventHappened(NotifyEventArgs e) { // User double clicked in the non client area (title bar most likely) } }
Links
License
Copyright (c) David Wendland. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for full license information.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
-
net8.0-windows7.0
- OneCore.Net.WIN.WinAPI (>= 1.0.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on OneCore.Net.WPF:
| Package | Downloads |
|---|---|
|
OneCore.Net.WPF.SystemTray
OneCore.Net.WPF.SystemTray is a library that provides all the necessary tools to create and manage custom, styled system tray icons in WPF applications. |
|
|
OneCore.Net.WPF.Theming
OneCore.Net.WPF.Theming is a library that simplifies working with themes and accent colors, enabling easy customization of the visual style in WPF applications. |
|
|
OneCore.Net.WPF.DragAndDrop
OneCore.Net.WPF.DragAndDrop is a library that provides objects and helpers to simplify implementing drag-and-drop functionality in WPF applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.