WPF HexEditor Samples
This directory contains various sample applications demonstrating different features and use cases of the WPF HexEditor control.
π Available Samples
π₯οΈ WPFHexEditor.Sample.CSharp
Platform: WPF (C#) Description: Main C# WPF sample application showcasing core features of the HexEditor control.
Features demonstrated:
- Opening and editing binary files
- Copy/paste operations (Ctrl+C, Ctrl+V)
- Undo/redo functionality (Ctrl+Z, Ctrl+Y)
- Find and replace dialogs
- Custom character table (TBL) support
- Multiple view modes (hexadecimal, decimal, binary)
- Bookmarks
- Selection operations
How to run:
cd WPFHexEditor.Sample.CSharp
dotnet run
π WpfHexEditor.Sample.VB
Platform: WPF (VB.NET) Description: Visual Basic .NET version of the WPF sample, demonstrating the same features for VB developers.
How to run:
cd WpfHexEditor.Sample.VB
dotnet run
π WpfHexEditor.Sample.BarChart
Platform: WPF (C#) Description: Advanced sample showing how to visualize binary data as a bar chart alongside the hex editor.
Features demonstrated:
- Real-time bar chart representation of byte values
- Visual data analysis
- Custom data visualization
- Synchronized scrolling between chart and hex view
Use cases:
- Analyzing file entropy
- Visualizing data patterns
- Finding compressed/encrypted sections
- Binary file analysis
πͺ WpfHexEditor.Sample.Winform
Platform: Windows Forms (C#) Description: Demonstrates how to integrate the WPF HexEditor control into a Windows Forms application using ElementHost.
Features demonstrated:
- WPF/WinForms interoperability
- ElementHost usage
- Cross-platform UI integration
How to run:
cd WpfHexEditor.Sample.Winform
dotnet run
π’ WpfHexEditor.Sample.AvalonDock
Platform: WPF (C#) Description: Shows integration with AvalonDock for professional docking and tabbed layouts.
Features demonstrated:
- Multiple hex editor instances in tabs
- Docking panels
- Professional IDE-like interface
- Floating windows
- Layout persistence
Use cases:
- Multi-file editing
- Professional binary editing tools
- IDE integration
- Advanced file comparison
π WpfHexEditor.Sample.InsertByteAnywhere
Platform: WPF (C#) Description: Demonstrates advanced byte insertion and deletion capabilities.
Features demonstrated:
- Insert bytes at any position
- Delete bytes from selection
- Dynamic file size modification
- Insert mode vs overwrite mode
Use cases:
- Binary file modification
- Data injection
- Binary patching
- File format manipulation
π WpfHexEditor.Sample.BinaryFilesDifference
Platform: WPF (C#) Description: Advanced sample for comparing two binary files and highlighting differences.
Features demonstrated:
- Side-by-side file comparison
- Difference highlighting with custom background colors
- Synchronized scrolling
- CustomBackgroundBlock API usage
Use cases:
- Binary diff tools
- Version comparison
- ROM hacking (comparing different versions)
- Patch analysis
π§ WpfHexEditor.Sample.ServiceUsage
Platform: Console (.NET 8.0) Description: Educational console application demonstrating direct usage of all 10 services without the HexEditor UI control.
Features demonstrated:
SelectionService- Selection validation and byte retrievalFindReplaceService- Search with cache optimizationClipboardService- Copy/paste operationsHighlightService- Managing highlighted byte positionsByteModificationService- Insert, delete, and modify bytesUndoRedoService- History managementBookmarkService- Bookmark creation and navigationCustomBackgroundService- Background color blocksPositionService- Position calculations and conversionsTblService- Character table operations
Use cases:
- Learning the service API architecture
- Building headless/automated binary processing tools
- Understanding how to use services independently
- Creating custom tools without the UI control
- Unit testing and service integration
How to run:
cd WpfHexEditor.Sample.ServiceUsage
dotnet run
Output: Console output showing the results of each service operation with sample data.
π Quick Start
Prerequisites
- .NET 8.0 SDK or .NET Framework 4.8
- Visual Studio 2022 or later (optional)
- Windows OS
Building All Samples
From the repository root:
cd Sources
dotnet build WpfHexEditorControl.sln
Running a Specific Sample
Navigate to the sample directory and run:
dotnet run --project <SampleProjectName>.csproj
Or open the solution in Visual Studio and set the desired sample as the startup project.
π Learning Path
Recommended order for learning:
-
Architecture First:
WpfHexEditor.Sample.ServiceUsageβ NEW! Understand the service layer architecture and how services work independently -
Start with:
WPFHexEditor.Sample.CSharpLearn the basics: opening files, editing, copy/paste, undo/redo -
Next:
WpfHexEditor.Sample.InsertByteAnywhereLearn advanced editing: insertion, deletion, dynamic modifications -
Then:
WpfHexEditor.Sample.BarChartLearn data visualization and analysis techniques -
Advanced:
WpfHexEditor.Sample.BinaryFilesDifferenceLearn file comparison and custom rendering -
Integration:
WpfHexEditor.Sample.AvalonDockLearn professional UI integration patterns -
Cross-platform:
WpfHexEditor.Sample.WinformLearn WPF/WinForms interoperability
π¨ Common Code Patterns
Opening a File
hexEditor.FileName = @"C:\path\to\file.bin";
Programmatic Selection
hexEditor.SelectionStart = 0x100;
hexEditor.SelectionStop = 0x1FF;
Finding Data
byte[] searchData = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F }; // "Hello"
long position = hexEditor.FindFirst(searchData);
Custom Character Table
hexEditor.LoadTblFile(@"C:\path\to\custom.tbl");
Handling Events
hexEditor.SelectionStartChanged += (s, e) =>
{
Console.WriteLine($"Selection at: 0x{hexEditor.SelectionStart:X}");
};
π οΈ Architecture Integration
All samples now use the new Service-based Architecture (10 services total):
Stateless Services (6):
SelectionService- Selection validation and manipulationFindReplaceService- Search with optimized cachingClipboardService- Copy/paste operationsByteModificationService- Insert/delete/modify bytesUndoRedoService- Undo/redo history managementPositionService- Position calculations and conversions
Stateful Services (4):
HighlightService- Search result highlightingBookmarkService- Bookmark managementCustomBackgroundService- Background color blocksTblService- Character table operations
Learn more:
- Services/README.md - Complete service documentation
- WpfHexEditor.Sample.ServiceUsage - Practical service usage examples
π Additional Resources
- Main README - Project overview and features
- Services Documentation - Architecture details
- Core Documentation - Core components
- NuGet Package - Get the library
π‘ Tips
- Performance: For large files (>100MB), consider using
AllowVisualByteAdressto view only a portion - Custom TBL: Create your own character tables for game modding or proprietary formats
- Events: Subscribe to events like
BytesModified,SelectionChangedfor reactive UI - Theming: Customize colors via properties like
ForegroundSecondColor,SelectionFirstColor
π Troubleshooting
Issue: Sample wonβt build Solution: Ensure youβre targeting .NET 8.0-windows or .NET Framework 4.8
Issue: File wonβt open Solution: Check file permissions and that the file exists
Issue: High memory usage
Solution: Use AllowVisualByteAdress for large files
π Contributing
Want to add a new sample? Please:
- Follow the naming convention:
WpfHexEditor.Sample.<FeatureName> - Include a README in your sample directory
- Add your sample to this index
- Submit a pull request
β¨ Created by Derek Tremblay (derektremblay666@gmail.com)