WpfHexEditorControl

Wpf Hexeditor is a powerful and fully customisable user control for editing file or stream as hexadecimal, decimal and binary. Can be used in Wpf or WinForm application

View project on GitHub

Core/Converters

WPF value converters for data type transformations in XAML bindings.

📁 Contents

🔄 Hex/Decimal Converters

👁️ Visibility Converters

🔀 Logic Converters

📂 File Converters

  • PathToFilenameConverter.cs - Full path to filename
    • Converts: "C:\folder\file.bin""file.bin"
    • Used in window titles and status bars

🎯 Purpose

WPF value converters enable data type transformations in XAML bindings without code-behind. These converters are used throughout the hex editor UI to display byte values, positions, and control visibility.

🎓 Usage Example

In XAML:

<Window.Resources>
    <converters:ByteToHexStringConverter x:Key="ByteToHex" Show0xTag="True"/>
    <converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>
    <converters:PathToFilenameConverter x:Key="PathToFilename"/>
</Window.Resources>

<!-- Display byte as hex -->
<TextBlock Text="{Binding ByteValue, Converter={StaticResource ByteToHex}}"/>
<!-- Result: "0xFF" -->

<!-- Show/hide based on boolean -->
<Button Visibility="{Binding IsEnabled, Converter={StaticResource BoolToVis}}"/>

<!-- Show filename only -->
<TextBlock Text="{Binding FilePath, Converter={StaticResource PathToFilename}}"/>
<!-- Input: "C:\data\file.bin" → Output: "file.bin" -->

In Code:

var converter = new ByteToHexStringConverter { Show0xTag = true };
string result = converter.Convert(255, null, null, null);
// Returns: "0xFF"

🔗 Architecture

All converters implement IValueConverter interface:

public interface IValueConverter
{
    object Convert(object value, Type targetType,
                   object parameter, CultureInfo culture);

    object ConvertBack(object value, Type targetType,
                       object parameter, CultureInfo culture);
}

✨ Features

  • Type Safety: Null-safe implementations
  • Culture Support: Respect regional settings
  • Two-Way Binding: ConvertBack for editable controls
  • Parameter Support: Optional converter parameters
  • Reusable: Used across all HexEditor UI

📍 Usage Locations

These converters are used in:

🎨 Converter Patterns

Simple Conversion:

public object Convert(object value, ...) =>
    value is byte b ? $"0x{b:X2}" : "N/A";

With Options:

public bool Show0xTag { get; set; } = true;

public object Convert(object value, ...) =>
    Show0xTag ? $"0x{val:X2}" : $"{val:X2}";

✨ WPF value converters for seamless data type transformations