Library that contains useful tools for WPF application.
It is recommended to use this library with Fody.PropertyChanged.
Main features:
- ObservableObject (
INotifyPropertyChangedimplementation) - IRefreshableCommand (inherits
ICommand, allows to callICommand.CanExecuteChangedmanually) - RelayCommand (
IRefreshableCommandimplementation) - RelayAsyncCommand (
IRefreshableCommandasync implementation) - RelaySingleTaskAsyncCommand (
IRefreshableCommandasync implementation, designed for single task execution)
Converters:
- InverseBooleanConverter
- BooleanToVisibilityConverter
- BooleanToHiddenVisibilityConverter
- InverseBooleanToHiddenVisibilityConverter
- InverseBooleanToVisibilityConverter
Extensions:
- ControlExtensions
FocusMode- focus mode forControl. There is two modes:DefaultandFocusOnLoad.
- HyperlinkExtensions
IsExternal- iftrueHyperlink will executeProcess.StartusingHyperlink.NavigateUriafter click.
- WindowExtensions
CloseCommand- command which executes on windows closing. IfICommand.CanExecute()returns false - window closing will be cancalled.CloseCommandParameter- parameter forCloseCommand.PlacementStorageStrategy- window placement storage strategy. There are 2 different implemented strategies,RegistryStorageandSettingsStorage. It is possible to implement custom strategy usingIWindowPlacementStorage.
- RoutedCommand bindings - allows to bind
ICommandtoRoutedCommand.
Services:
- IWindowService - (implementation: WindowService)
IsActive- indicates whether the window is active.IsVisible- indicates whether the window is visible.Activate()- attempts to brind the window to the foreground and activates it.Close()- closes window.Close(bool dialogResult)- closes window with specified dialog result.Hide()- hides window.Show()- shows window.
- ITextBoxService - (implementation: TextBoxService)
- event
TextChanged- informs that the text has changed. - event
SelectionChanged- informs that the selection has changed. Text- allows to get or set text toTextBox(will not break bindings).CaretIndex- gets current caret index.SelectionLength- gets selected text length.SelectedText- gets or sets selected text in text box (will not break bindings).Select(int start, int length)- selects a range of text in text box.SelectAll()- selects all text in text box.
- event
- IPasswordSupplier - (implementation: PasswordSupplier)
- event
PasswordChanged- occurs when the password of thePasswordBoxchanges. Password- allows to get or set password from/toPasswordBox.SecurePassword- gets secure password fromPasswordBox.Clear()- clears all password.
- event
Use one of the follwing methods to install and use this library:
-
Package Manager:
PM> Install-Package UToolKit -
.NET CLI:
> dotnet add package UToolKit
First you need to include namespace to your code or markup.
For XAML it can look like:
<Window xmlns:tk="https://github.com/nullsoftware/UToolKit" />And for C#:
using NullSoftware;
using NullSoftware.Services;
using NullSoftware.ToolKit;
using NullSoftware.ToolKit.Converters;
using NullSoftware.ToolKit.Extensions;To use converters just add MergedDictionary with source pack://application:,,,/UToolKit;component/ToolKit/Converters.xaml in your App.xaml:
<Application
x:Class="ExampleProject.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ExampleProject"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/UToolKit;component/ToolKit/Converters.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>How to set PlacementStorageStrategy:
<Window xmlns:tk="https://github.com/nullsoftware/UToolKit"
tk:WindowExtensions.PlacementStorageStrategy="{tk:RegistryStorage}" />
<!--also there is possible to specify name or other registry storage properties-->
<Window xmlns:tk="https://github.com/nullsoftware/UToolKit"
tk:WindowExtensions.PlacementStorageStrategy="{tk:RegistryStorage NameFormat=Placement, Hive=CurrentUser, Key='SOFTWARE\MyCompany\MyApp'}" />or
<Window xmlns:tk="https://github.com/nullsoftware/UToolKit"
xmlns:prop="clr-namespace:ExampleProject.Properties"
tk:WindowExtensions.PlacementStorageStrategy="{tk:SettingsStorage Settings={x:Static prop:Settings.Default}}" />How to use RoutedCommandHandlers:
<Window xmlns:tk="https://github.com/nullsoftware/UToolKit">
<!-- here we bind ICommand to RouteUICommand -->
<tk:RoutedCommandHandlers.Commands>
<tk:RoutedCommandHandler RoutedCommand="ApplicationCommands.Create" Command="{Binding CreateCommand}"/>
<tk:RoutedCommandHandler RoutedCommand="ApplicationCommands.Open" Command="{Binding OpenCommand}"/>
</tk:RoutedCommandHandlers.Commands>
<!-- here our app content -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Menu Grid.Row="0">
<MenuItem Header="_File">
<MenuItem Header="_New" Command="ApplicationCommands.Create" />
<MenuItem Header="_Open" Command="ApplicationCommands.Open" />
</MenuItem>
</Menu>
</Grid>
</Window>