Skip to content

Commit ba2bb70

Browse files
author
Peter
committed
README.md
1 parent c97cc01 commit ba2bb70

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

CustomControlBaseLib.sln

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomControlSample", "Cust
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomControlSampleLib", "CustomControlSampleLib\CustomControlSampleLib.csproj", "{086A3184-0414-49C5-8EDE-22769BDFC569}"
1111
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1D1115C6-C797-4376-8B86-349094F45C0E}"
13+
ProjectSection(SolutionItems) = preProject
14+
CustomControlSample.pdn = CustomControlSample.pdn
15+
CustomControlSample.png = CustomControlSample.png
16+
README.md = README.md
17+
EndProjectSection
18+
EndProject
1219
Global
1320
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1421
Debug|Any CPU = Debug|Any CPU

CustomControlSample.pdn

95.8 KB
Binary file not shown.

CustomControlSample.png

51.6 KB
Loading

CustomControlSample/MainWindow.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:local="clr-namespace:CustomControlSample"
77
xmlns:CustomControlSampleLib="clr-namespace:CustomControlSampleLib;assembly=CustomControlSampleLib"
88
mc:Ignorable="d"
9-
Title="MainWindow" Width="500" Height="400">
9+
Title="MainWindow" Width="400" Height="300">
1010
<Grid>
1111
<Grid.RowDefinitions>
1212
<RowDefinition/>
@@ -16,7 +16,7 @@
1616
</Grid.RowDefinitions>
1717
<Grid.ColumnDefinitions>
1818
<ColumnDefinition Width="Auto"/>
19-
<ColumnDefinition Width="200"/>
19+
<ColumnDefinition Width="100"/>
2020
<ColumnDefinition Width="50"/>
2121
<ColumnDefinition/>
2222
</Grid.ColumnDefinitions>

README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
![User has changed data, cannot close window](CustomControlSample.png)
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

Comments
 (0)