|
| 1 | +# Base WPF functionality for writing custom controls |
| 2 | + |
| 3 | +## Table of content |
| 4 | +[About](#about) |
| 5 | +[Sample](#sample) |
| 6 | +[Build requirements](#Build-requirements) |
| 7 | +[Structure CustomControlBaseLib Solution](#Structure-CustomControlBaseLib-Solution) |
| 8 | +[Project Status](#Project-Status) |
| 9 | +[Copyright](#Copyright) |
| 10 | + |
| 11 | +## About |
| 12 | + |
| 13 | +It can be quite a lot of work to support resizing, padding, different fonts, etc. |
| 14 | +when you write a WPF custom control. The main class in the library `CustomControlBase` |
| 15 | +provides these functionalities and also drawing directly to the screen for your |
| 16 | +custom control. |
| 17 | +A few other methods in this library are also helpful when writing |
| 18 | +WPF controls, like `GlyphDrawer` which allows to measure text length and |
| 19 | +writing text directly to a Control's DrawingContext. |
| 20 | + |
| 21 | +## Sample |
| 22 | + |
| 23 | +`CustomControlBase` can be used for any custom control. `CustomControlSample` in |
| 24 | +`CustomControlSampleLib` provides a detailed example how to add `Visuals`, |
| 25 | +`FramworkElemtens`, `Controls`, etc. and how to directly |
| 26 | +draw to the screen can be easily combined. Left in the sample is a `TextBox` and right |
| 27 | +is a code drawn ellipse with the same (!) size like the TextBox. A possible use case would |
| 28 | +be a graph together with legend. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +One challenge here is the sizing and placing of the control's content, depending on Alignment (stretched or not), |
| 33 | +`TextBox.FontSize` and available space given by the Window. `CustomControlBase` and |
| 34 | +`CustomControlSample` also support Border and Padding. `Font` and `BackGround` are inherited in a custom |
| 35 | +control from `Control`, but they don't do anything out of the box. `CustomControlBase` adds the missing |
| 36 | +functionality. |
| 37 | + |
| 38 | +## Build requirements |
| 39 | +.Net Core 3.1 or later |
| 40 | + |
| 41 | +## Structure CustomControlBaseLib Solution |
| 42 | + |
| 43 | +### CustomControlBaseLib |
| 44 | +The only library needed to be referenced from other code, providing: |
| 45 | +* `CustomControlBase`: Base class for custom controls with functionality added for Children, Drawing, |
| 46 | +`Border`, `Padding` and `Background`. |
| 47 | +* `GlyphDrawer`: Writes text to a `DrawingContext`. Can also be used to calculate the length of text. |
| 48 | +### CustomControlSample |
| 49 | +Shows how to use `CustomControlBase` |
| 50 | +### CustomControlSampleLib |
| 51 | +Helper library for `CustomControlSample` |
| 52 | + |
| 53 | +## Project Status |
| 54 | +Completed and stable |
| 55 | + |
| 56 | +## Copyright |
| 57 | +Copyright 2020 Jürg Peter Huber, Singapore. |
| 58 | + |
| 59 | +Licensed under the [Creative Commons 0 license](COPYING.txt) |
| 60 | + |
0 commit comments