Skip to content

Commit

Permalink
README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Mar 8, 2020
1 parent c97cc01 commit ba2bb70
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CustomControlBaseLib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomControlSample", "Cust
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomControlSampleLib", "CustomControlSampleLib\CustomControlSampleLib.csproj", "{086A3184-0414-49C5-8EDE-22769BDFC569}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1D1115C6-C797-4376-8B86-349094F45C0E}"
ProjectSection(SolutionItems) = preProject
CustomControlSample.pdn = CustomControlSample.pdn
CustomControlSample.png = CustomControlSample.png
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Binary file added CustomControlSample.pdn
Binary file not shown.
Binary file added CustomControlSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions CustomControlSample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:CustomControlSample"
xmlns:CustomControlSampleLib="clr-namespace:CustomControlSampleLib;assembly=CustomControlSampleLib"
mc:Ignorable="d"
Title="MainWindow" Width="500" Height="400">
Title="MainWindow" Width="400" Height="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
Expand All @@ -16,7 +16,7 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
Expand Down
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Base WPF functionality for writing custom controls

## Table of content
[About](#about)
[Sample](#sample)
[Build requirements](#Build-requirements)
[Structure CustomControlBaseLib Solution](#Structure-CustomControlBaseLib-Solution)
[Project Status](#Project-Status)
[Copyright](#Copyright)

## About

It can be quite a lot of work to support resizing, padding, different fonts, etc.
when you write a WPF custom control. The main class in the library `CustomControlBase`
provides these functionalities and also drawing directly to the screen for your
custom control.
A few other methods in this library are also helpful when writing
WPF controls, like `GlyphDrawer` which allows to measure text length and
writing text directly to a Control's DrawingContext.

## Sample

`CustomControlBase` can be used for any custom control. `CustomControlSample` in
`CustomControlSampleLib` provides a detailed example how to add `Visuals`,
`FramworkElemtens`, `Controls`, etc. and how to directly
draw to the screen can be easily combined. Left in the sample is a `TextBox` and right
is a code drawn ellipse with the same (!) size like the TextBox. A possible use case would
be a graph together with legend.

![User has changed data, cannot close window](CustomControlSample.png)

One challenge here is the sizing and placing of the control's content, depending on Alignment (stretched or not),
`TextBox.FontSize` and available space given by the Window. `CustomControlBase` and
`CustomControlSample` also support Border and Padding. `Font` and `BackGround` are inherited in a custom
control from `Control`, but they don't do anything out of the box. `CustomControlBase` adds the missing
functionality.

## Build requirements
.Net Core 3.1 or later

## Structure CustomControlBaseLib Solution

### CustomControlBaseLib
The only library needed to be referenced from other code, providing:
* `CustomControlBase`: Base class for custom controls with functionality added for Children, Drawing,
`Border`, `Padding` and `Background`.
* `GlyphDrawer`: Writes text to a `DrawingContext`. Can also be used to calculate the length of text.
### CustomControlSample
Shows how to use `CustomControlBase`
### CustomControlSampleLib
Helper library for `CustomControlSample`

## Project Status
Completed and stable

## Copyright
Copyright 2020 Jürg Peter Huber, Singapore.

Licensed under the [Creative Commons 0 license](COPYING.txt)

0 comments on commit ba2bb70

Please sign in to comment.