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
                    
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="OneCore.Net.WPF" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OneCore.Net.WPF" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="OneCore.Net.WPF" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OneCore.Net.WPF --version 1.0.3
                    
#r "nuget: OneCore.Net.WPF, 1.0.3"
                    
#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.
#:package OneCore.Net.WPF@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OneCore.Net.WPF&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=OneCore.Net.WPF&version=1.0.3
                    
Install as a Cake Tool

OneCore

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

  1. Installation:

    • Install the OneCore.Net.WPF library via NuGet Package Manager:
    dotnet add package OneCore.Net.WPF
    
  2. BindingAdapter:

    • 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>
    
  3. ControlFocus:

    • Usage.
    public class MyControl : Control
    {
        protected void OnGotFocus()
        {
            ControlFocus.GiveFocus(myButton);
        }
    }
    
  4. IconReader:

    Icon icon = new Icon
    {
        Source = IconReader.FileIcon("C:\\path\\Demo.exe", false, false)
    }
    
  5. 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();
        }
    }
    
  6. MouseHelper

    • Check if the mouse is within a control.
    protected override void OnPreviewQueryContinueDrag(QueryContinueDragEventArgs e)
    {
        if (_dropPreviewAdorner == null)
            return;
    
        if (!MouseHelper.IsMouseInside(this))
            RemovePreviews();
    }
    
  7. 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()
        {
        }
    }
    
  8. SystemTexts:

    • Load the translation for the "Cancel" button from windows.
    var cancelLabel = SystemTexts.GetString(SystemTexts.CANCEL_CAPTION);
    
  9. 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"));
        }
    }
    
  10. 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);
    
  11. 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();
    }
    
  12. 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)
        }
    }
    

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 Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
1.0.3 406 12/11/2025
1.0.2 182 11/6/2025
1.0.1 190 11/5/2025
1.0.0 259 10/23/2025