Shos.Windows 1.0.0

dotnet add package Shos.Windows --version 1.0.0
                    
NuGet\Install-Package Shos.Windows -Version 1.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="Shos.Windows" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shos.Windows" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Shos.Windows" />
                    
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 Shos.Windows --version 1.0.0
                    
#r "nuget: Shos.Windows, 1.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.
#:package Shos.Windows@1.0.0
                    
#: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=Shos.Windows&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Shos.Windows&version=1.0.0
                    
Install as a Cake Tool

Shos.Windows

English | 日本語

build NuGet License: MIT

A small WPF library for .NET 8.0 and .NET 10.0.

Installation

Install from NuGet: NuGet Gallery | Shos.Windows

dotnet add package Shos.Windows

Requirements

  • .NET 8.0 (net8.0-windows) or .NET 10.0 (net10.0-windows)
  • WPF (<UseWPF>true</UseWPF>)

Class Diagram

The public types and members of Shos.Windows (+: public, #: protected, underlined: static). ComboBox (System.Windows.Controls) and IValueConverter (System.Windows.Data) are WPF types.

classDiagram
    direction LR

    class ComboBox
    class IValueConverter {
        <<interface>>
    }

    namespace Shos.Windows.Controls {
        class FontComboBox {
            +DependencyProperty SelectedFontFamilyProperty$
            +DependencyProperty SelectedFontFamilyNameProperty$
            +DependencyProperty SelectedLocalFontFamilyNameProperty$
            +FontFamily? SelectedFontFamily
            +string SelectedFontFamilyName
            +string SelectedLocalFontFamilyName
            +FontComboBox()
            #OnSelectionChanged(SelectionChangedEventArgs e) void
        }
    }

    namespace Shos.Windows.Data {
        class EnumToBooleanConverter {
            +Convert(object? value, Type targetType, object? parameter, CultureInfo culture) object
            +ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) object
        }
    }

    ComboBox <|-- FontComboBox
    IValueConverter <|.. EnumToBooleanConverter

Controls

FontComboBox

Namespace: Shos.Windows.Controls

Derives from System.Windows.Controls.ComboBox.

A combo box to select one of the system font families.

  • Each item is drawn with its own font. Symbol fonts (e.g. Marlett, Wingdings) are drawn with the default font so that their names stay readable.
  • Items are shown by their localized names (for the current culture) and sorted by them. Typing a name selects the matching item.
  • Items are virtualized, so the drop-down opens quickly even when many fonts are installed.
  • The font list is built once and shared by all instances.
Properties

The following properties are kept synchronized with each other and with SelectedItem, and bind two-way by default. Names are compared case-insensitively. When a value that matches no system font is set, the selection is cleared (SelectedFontFamily becomes null, and the name properties become "").

Property Type Default Description
SelectedFontFamily FontFamily? SystemFonts.MenuFontFamily The selected font family.
SelectedFontFamilyName string Name of the default font family The name (FontFamily.Source) of the selected font family. e.g. "Yu Gothic UI"
SelectedLocalFontFamilyName string Localized name of the default font family The localized name (for the current culture) of the selected font family. e.g. "游ゴシック UI"
Example
<Window xmlns:shoswindowscontrols="clr-namespace:Shos.Windows.Controls;assembly=Shos.Windows" ...>
    <StackPanel>
        <shoswindowscontrols:FontComboBox SelectedFontFamilyName="{Binding SelectedFontFamilyName}" />
        <TextBox FontFamily="{Binding SelectedFontFamilyName}" />
    </StackPanel>
</Window>

You can also bind the FontFamily object directly:

<shoswindowscontrols:FontComboBox x:Name="fontComboBox" />
<TextBox FontFamily="{Binding SelectedFontFamily, ElementName=fontComboBox}" />

Converters

EnumToBooleanConverter

Namespace: Shos.Windows.Data

Implements System.Windows.Data.IValueConverter.

Used to bind multiple radio buttons to a single enum property.

  • Convert: returns true when the enum value equals the converter parameter, otherwise false.
  • ConvertBack: returns the converter parameter when the value is true. Otherwise (e.g. when a radio button is unchecked) the source is not updated (Binding.DoNothing).

The converter parameter can be either:

  • the enum value itself (e.g. ConverterParameter={x:Static local:FontSizeKind.Small}), or
  • the name of an enum member (e.g. ConverterParameter=Small).

Nullable enum properties (e.g. FontSizeKind?) are also supported. When the value is not an enum or the parameter does not match the enum type, Convert returns DependencyProperty.UnsetValue.

Example
public enum FontSizeKind { Small, Medium, Large }
<Window xmlns:shoswindowsdata="clr-namespace:Shos.Windows.Data;assembly=Shos.Windows"
        xmlns:local="clr-namespace:YourApp" ...>
    <Window.Resources>
        <shoswindowsdata:EnumToBooleanConverter x:Key="enumToBooleanConverter" />
    </Window.Resources>
    <StackPanel>
        <RadioButton Content="Small"  IsChecked="{Binding FontSizeKind, Converter={StaticResource enumToBooleanConverter}, ConverterParameter={x:Static local:FontSizeKind.Small}}" />
        <RadioButton Content="Medium" IsChecked="{Binding FontSizeKind, Converter={StaticResource enumToBooleanConverter}, ConverterParameter={x:Static local:FontSizeKind.Medium}}" />
        <RadioButton Content="Large"  IsChecked="{Binding FontSizeKind, Converter={StaticResource enumToBooleanConverter}, ConverterParameter={x:Static local:FontSizeKind.Large}}" />
    </StackPanel>
</Window>

Projects

Project Description
Shos.Windows The library (namespaces: Shos.Windows.Controls, Shos.Windows.Data)
Shos.Windows.Sample A WPF sample app using Shos.Windows
Shos.Windows.Tests Unit tests (xUnit)

Building from Source

Requires Windows and the .NET 10.0 SDK (plus the .NET 8.0 runtime to run the tests for net8.0-windows).

git clone https://github.com/Fujiwo/Shos.Windows.git
cd Shos.Windows
dotnet build Shos.Windows.sln --configuration Release
dotnet test Shos.Windows.sln --configuration Release --no-build

The NuGet package (containing both net8.0-windows and net10.0-windows assemblies) is generated in Shos.Windows/bin/Release/.

Author Info

Fujio Kojima: a software developer in Japan

  • Microsoft MVP for Development Tools - Visual C# (Jul. 2005 - Dec. 2014)
  • Microsoft MVP for .NET (Jan. 2015 - Oct. 2015)
  • Microsoft MVP for Visual Studio and Development Technologies (Nov. 2015 - Jun. 2018)
  • Microsoft MVP for Developer Technologies (Nov. 2018 - Jun. 2027)
  • MVP Profile
  • Blog (Japanese)
  • Web Site (Japanese)

License

This library is under the MIT License.

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.  net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

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
1.0.0 78 10/10/2026
0.3.2 275 3/28/2024
0.3.1 229 3/26/2024
0.3.0 710 10/17/2019