CanvasControl Class
Represents a control that supports custom rendering of content.
public class CanvasControl : Control, ICanvas
- Inheritance:
- object Visual UIElement FrameworkElement Control object
- Implements:
- ICanvas
Constructors
CanvasControl()
Initializes an instance of the class.
public CanvasControl()
CanvasControl(bool)
Initializes an instance of the class.
public CanvasControl(bool isForPrinter)
| Parameter | Type | Description |
|---|---|---|
| isForPrinter | bool | Whether this canvas is created for a printer. |
Properties
IsForPrinter
Indicates whether this canvas is created for a printer.
protected bool IsForPrinter { get; }
Property Value
- bool:
trueif this canvas is created for a printer; otherwise,false.
Methods
CreateDrawContext(ICanvas, DrawingContext, Rect)
Creates a CanvasDrawContext for the Draw event.
protected virtual CanvasDrawContext CreateDrawContext(ICanvas canvas, DrawingContext platformRenderer, Rect bounds)
| Parameter | Type | Description |
|---|---|---|
| canvas | ICanvas | The ICanvas being drawn. |
| platformRenderer | DrawingContext | The native object used for drawing. |
| bounds | Rect | The bounds in which to draw. |
Returns
CreateTextBatch()
Creates an IDisposable object that contains a reference to a text renderer, which can be passed to the RunTextFormatter(IDisposable?) to more efficiently process multiple similar text layouts in a batch.
public IDisposable CreateTextBatch()
Returns
- IDisposable:
An IDisposable object. Once disposed, the batch is ended.
CreateTextLayout(ITextProvider, float, string, float, Brush, IEnumerable<ITextSpacer>?)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(ITextProvider textProvider, float maxWidth, string fontFamilyName, float fontSize, Brush foreground, IEnumerable<ITextSpacer>? spacers)
| Parameter | Type | Description |
|---|---|---|
| textProvider | ITextProvider | An ITextProvider that provides access to the text string. |
| maxWidth | float | The maximum width of the layout, which is used if word wrap is enabled. |
| fontFamilyName | string | The default font family name. |
| fontSize | float | The default font size. |
| foreground | Brush | The default foreground. |
| spacers | IEnumerable<ITextSpacer> | The optional intra-text spacers. |
Returns
CreateTextLayout(ITextProvider, float, string, float, Brush, FontWeight, FontStyle, IEnumerable<ITextSpacer>?)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(ITextProvider textProvider, float maxWidth, string fontFamilyName, float fontSize, Brush foreground, FontWeight fontWeight, FontStyle fontStyle, IEnumerable<ITextSpacer>? spacers)
| Parameter | Type | Description |
|---|---|---|
| textProvider | ITextProvider | An ITextProvider that provides access to the text string. |
| maxWidth | float | The maximum width of the layout, which is used if word wrap is enabled. |
| fontFamilyName | string | The default font family name. |
| fontSize | float | The default font size. |
| foreground | Brush | The default foreground. |
| fontWeight | FontWeight | The default font weight. |
| fontStyle | FontStyle | The default font style. |
| spacers | IEnumerable<ITextSpacer> | The optional intra-text spacers. |
Returns
CreateTextLayout(ITextProvider, float, string, float, Color, IEnumerable<ITextSpacer>?)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(ITextProvider textProvider, float maxWidth, string fontFamilyName, float fontSize, Color foreground, IEnumerable<ITextSpacer>? spacers)
| Parameter | Type | Description |
|---|---|---|
| textProvider | ITextProvider | An ITextProvider that provides access to the text string. |
| maxWidth | float | The maximum width of the layout, which is used if word wrap is enabled. |
| fontFamilyName | string | The default font family name. |
| fontSize | float | The default font size. |
| foreground | Color | The default foreground. |
| spacers | IEnumerable<ITextSpacer> | The optional intra-text spacers. |
Returns
CreateTextLayout(ITextProvider, float, string, float, Color, FontWeight, FontStyle, IEnumerable<ITextSpacer>?)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(ITextProvider textProvider, float maxWidth, string fontFamilyName, float fontSize, Color foreground, FontWeight fontWeight, FontStyle fontStyle, IEnumerable<ITextSpacer>? spacers)
| Parameter | Type | Description |
|---|---|---|
| textProvider | ITextProvider | An ITextProvider that provides access to the text string. |
| maxWidth | float | The maximum width of the layout, which is used if word wrap is enabled. |
| fontFamilyName | string | The default font family name. |
| fontSize | float | The default font size. |
| foreground | Color | The default foreground. |
| fontWeight | FontWeight | The default font weight. |
| fontStyle | FontStyle | The default font style. |
| spacers | IEnumerable<ITextSpacer> | The optional intra-text spacers. |
Returns
CreateTextLayout(string, float, string, float, Brush)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(string text, float maxWidth, string fontFamilyName, float fontSize, Brush foreground)
| Parameter | Type | Description |
|---|---|---|
| text | string | The text string. |
| maxWidth | float | The maximum width of the layout, which is used if word wrap is enabled. |
| fontFamilyName | string | The default font family name. |
| fontSize | float | The default font size. |
| foreground | Brush | The default foreground. |
Returns
CreateTextLayout(string, float, string, float, Color)
Creates an ITextLayout that can render text runs on a canvas.
public ITextLayout CreateTextLayout(string text, float maxWidth, string fontFamilyName, float fontSize, Color foreground)
| Parameter | Type | Description |
|---|---|---|
| text | string | The text string. |
| maxWidth | float | The maximum width of the layout, which is used if word wrap is enabled. |
| fontFamilyName | string | The default font family name. |
| fontSize | float | The default font size. |
| foreground | Color | The default foreground. |
Returns
CreateTextSpacer(int, object, Size, double)
Creates an ITextSpacer that can create intra-text space within an ITextLayout.
public ITextSpacer CreateTextSpacer(int characterIndex, object key, Size size, double baseline)
| Parameter | Type | Description |
|---|---|---|
| characterIndex | int | The character index at which the spacer should be inserted. |
| key | object | An optional object that uniquely identifies the spacer. |
| size | Size | The size of the spacer. |
| baseline | double | The baseline of the spacer. |
Returns
ExecuteFunc<T>(Func<T>)
Safely executes a Func<TResult> that deals with canvas resource creation and occurs outside of the Draw event handler.
public T? ExecuteFunc<T>(Func<T> func)
- Type Parameters:
-
T-
| Parameter | Type | Description |
|---|---|---|
| func | Func<T> | The Func<TResult> to execute. |
Returns
- T:
trueif the canvas was ready and executed the function; otherwise,false.
GetSolidColorBrush(Color)
Returns a solid color brush for the specified color.
public SolidColorBrush GetSolidColorBrush(Color color)
| Parameter | Type | Description |
|---|---|---|
| color | Color | The brush color. |
Returns
GetSquiggleLinePen(Color)
Returns a squiggle line pen for the specified color.
public Pen GetSquiggleLinePen(Color color)
| Parameter | Type | Description |
|---|---|---|
| color | Color | The pen color. |
Returns
GetSquiggleLinePen(Color, float)
Returns a squiggle line pen for the specified color.
public Pen GetSquiggleLinePen(Color color, float thickness)
| Parameter | Type | Description |
|---|---|---|
| color | Color | The pen color. |
| thickness | float | The pen thickness. |
Returns
InvalidateRender()
Invalidates and repaints the control.
public void InvalidateRender()
OnRender(DrawingContext)
When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
protected override void OnRender(DrawingContext drawingContext)
| Parameter | Type | Description |
|---|---|---|
| drawingContext | DrawingContext | The drawing instructions for a specific element. This context is provided to the layout system. |
Events
Draw
Occurs when the canvas should be rendered.