# Integrating WPF Barcodes and Drawings

> Insert barcodes and drawings into WPF documents: BarcodeFrame, TXDrawingControl shapes with fill, outline and z-order, the Insert tab and TXBarcodeCore SVG.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Integration Guide > Integrating WPF Barcodes and Drawings
- **6382 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/barcodes-drawings/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/barcodes-drawings/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/barcodes-drawings/llms-full.txt

---

Barcodes and drawings sit in a WPF document like images: inline in the text, anchored to a paragraph or at a fixed position on the page. Each is a frame in the document that holds a WPF element drawing its content -- a barcode control for barcodes, a drawing control with shapes for drawings. Both come with the TX Text Control package, so no further reference is needed. The sections below show how the parts fit together, how the ribbon offers them to users, and how your code inserts them.

The WPF `TextControl` has no chart objects: it has no `Charts` collection and no ribbon tab for charts, which the Windows Forms product has. How users format and position barcodes in the editor is described in [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/charts-barcodes/llms-full.txt) and [Text Frames and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/text-frames-shapes/llms-full.txt).

### What Each Object Is Made of

|  | Barcode | Drawing |
|---|---|---|
| The object in the document | [BarcodeFrame](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/barcodeframe/llms-full.txt) | [DrawingFrame](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/drawingframe/llms-full.txt) |
| The WPF element that draws it | [TXBarcodeControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-barcode/txbarcodecontrol/llms-full.txt) in `TXTextControl.WPF.Barcode` | [TXDrawingControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/llms-full.txt) in `TXTextControl.WPF.Drawing`, which holds [Shape](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/llms-full.txt) objects |
| All of them in the text part with the input focus | [TextControl.Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/barcodes-property/llms-full.txt) | [TextControl.Drawings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/drawings-property/llms-full.txt) |
| The assemblies | *TXBarcode.dll* and *TXBarcode.WPF.dll* | *TXDrawing.dll* and *TXDrawing.WPF.dll* |

The frame, in the namespace `TXTextControl.DataVisualization`, handles the position in the text; the element holds the content, such as the barcode type and its data or the shapes of a drawing. The collections of the `TextControl` refer to the text part with the input focus: the main text, a header or footer, or a text frame. The class diagram of the barcode classes shows the frame, the collection and the two barcode controls for Windows Forms and WPF:

![A class diagram of the barcode classes: TextControl and WPF.TextControl with the Barcodes property, BarcodeCollection, BarcodeFrame, TXBarcodeControl and WPF.TXBarcodeControl, and BarcodeTypeSettings.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/barcodes-class-diagram.df5a7e7c.webp)

The package `TXTextControl.TextControl.WPF.SDK` contains all four assemblies. A window that declares a barcode or drawing element in XAML maps its namespace with a prefix of its own, as [Assemblies and XAML Namespaces](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/installation/xaml-namespaces/#declare-further-namespaces) shows; usually, they are created in code.

### Offer Barcodes and Drawings in the Ribbon

The [RibbonInsertTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribboninserttab/llms-full.txt) has an item that inserts a barcode, `TXITEM_InsertBarcode`, and a drop-down for shapes, `TXITEM_InsertShape`. The drop-down lists the shapes in categories, such as lines, rectangles, basic shapes, block arrows, equation shapes, flowchart shapes, stars and banners, and callouts, and has an item for a drawing canvas that holds several shapes, `TXITEM_InsertDrawingCanvas`. The [RibbonFrameLayoutTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonframelayouttab/llms-full.txt) edits the layout of selected images, text frames, drawings and barcodes.

Connect both tabs to the editor by name, through [RibbonInsertTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribboninserttab-property/llms-full.txt) and [RibbonFrameLayoutTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribbonframelayouttab-property/llms-full.txt) of the `TextControl`, as [Connecting Ribbon Tabs in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon-xaml/llms-full.txt) shows. Without a ribbon, [BarcodeLayoutDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/barcodelayoutdialog-method/llms-full.txt) and [DrawingLayoutDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/drawinglayoutdialog-method/llms-full.txt) open dialog boxes for the layout of the selected object.

### Insert a Barcode in Code

Code inserts a barcode in two steps: it sets the type and the text of a WPF `TXBarcodeControl` and adds a `BarcodeFrame` that holds it to [TextControl.Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/barcodes-property/llms-full.txt). The text position -1 inserts the barcode inline at the input position; other overloads anchor it to a paragraph or place it at a fixed position. [Insert a Barcode From Code](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/charts-barcodes/#insert-a-barcode-from-code) shows the code, the barcode types and how to change the text of the selected barcode.

### Insert a Drawing in Code

A drawing is inserted the same way: a [TXDrawingControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/llms-full.txt), a canvas that holds one or more shapes, goes into a [DrawingFrame](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/drawingframe/llms-full.txt), which [TextControl.Drawings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/drawings-property/llms-full.txt) adds to the document. [Insert a Shape From Code](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/text-frames-shapes/#insert-a-shape-from-code) inserts a single shape that fills its drawing. [Shape](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/llms-full.txt) and [ShapeType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shapetype/enumeration/llms-full.txt) are shared with Windows Forms, in `TXTextControl.Drawing`, while the drawing classes of WPF and Windows Forms differ in a few members, such as the context menu of shapes; the class diagram on that page marks them.

The examples below add their buttons to a window with a `TextControl` named `textControl1` and their handlers to *MainWindow.xaml.cs*.

### Work With the Shapes of a Drawing

The shapes of a drawing are programmed through its [TXDrawingControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/llms-full.txt): its [Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapes-property/llms-full.txt) hold the shapes, its [Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/selection-property/llms-full.txt) the shapes the user selected, and its events report what happens to a shape. For a drawing that is already in the document, [DrawingFrame.Drawing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/drawingframe/drawing-property/llms-full.txt) returns the drawing control; it is typed `object`, so cast it to the WPF class.

#### Draw Shapes With a Fill and an Outline

The following handler inserts a drawing canvas with two overlapping shapes and reports each shape the user selects:

```csharp
using System.Windows;
using TXTextControl.DataVisualization;
using TXTextControl.Drawing;
using TXTextControl.WPF.Drawing;

private void insertCanvasButton_Click(object sender, RoutedEventArgs e)
{
    TXDrawingControl drawing = new TXDrawingControl();

    // A canvas of 2 x 1 inches, in twips
    drawing.SetCanvasSize(2880, 1440);

    TXTextControl.Drawing.Shape box = new TXTextControl.Drawing.Shape(ShapeType.RoundRectangle)
    {
        Location = new System.Drawing.Point(144, 144),
        Size = new System.Drawing.Size(1800, 1000)
    };
    box.ShapeFill.Color = System.Drawing.Color.LightSteelBlue;
    box.ShapeOutline.Color = System.Drawing.Color.DarkBlue;
    box.ShapeOutline.Width = 40;

    TXTextControl.Drawing.Shape star = new TXTextControl.Drawing.Shape(ShapeType.Star5)
    {
        Location = new System.Drawing.Point(1440, 288),
        Size = new System.Drawing.Size(1000, 1000),
        Angle = 15
    };
    star.ShapeFill.Color = System.Drawing.Color.Gold;

    // Each shape is drawn at its own location and size
    drawing.Shapes.Add(box);
    drawing.Shapes.Add(star);

    drawing.ShapeSelected += Drawing_ShapeSelected;

    textControl1.Drawings.Add(new DrawingFrame(drawing), -1);
    textControl1.Focus();
}

private void Drawing_ShapeSelected(object sender, ShapeEventArgs e)
{
    TXTextControl.Drawing.Shape shape = e.Shape;
    Title = $"{shape.Type}: {shape.Size.Width} x {shape.Size.Height} twips, angle {shape.Angle}";
}
```

The code works as follows:

- [SetCanvasSize](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/setcanvassize-method/llms-full.txt) sets the width and height of the canvas in twips, at a zoom factor of 100 percent.
- [Location](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/location-property/llms-full.txt) and [Size](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/size-property/llms-full.txt) of a shape are in twips from the top-left corner of the canvas, and [Angle](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/angle-property/llms-full.txt) rotates it. [ShapeCollection.Add](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shapecollection/add-method/llms-full.txt) without an `AddStyle` draws the shape at that location and size.
- [ShapeFill](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/shapefill-property/llms-full.txt) and [ShapeOutline](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/shapeoutline-property/llms-full.txt) are read-only properties that return objects of the nested classes [Shape.Fill](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape-fill/llms-full.txt) and [Shape.Outline](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape-outline/llms-full.txt). Their `Color` is a `System.Drawing.Color`, and the outline [Width](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape-outline/width-property/llms-full.txt) is in twips, 20 by default.
- [ShapeSelected](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapeselected-event/llms-full.txt) passes a [ShapeEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shapeeventargs/llms-full.txt) whose [Shape](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shapeeventargs/shape-property/llms-full.txt) is the selected shape.
- `Shape` is written with its namespace because `System.Windows.Shapes`, which the WPF project template imports, has a `Shape` class too.

Shapes have further properties: [Movable](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/movable-property/llms-full.txt) and [Sizable](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/sizable-property/llms-full.txt), both `true` by default, decide whether users can move and size a shape; [IsSelected](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/isselected-property/llms-full.txt) and [Index](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/index-property/llms-full.txt) tell whether a shape is selected and where it is in the collection; [FitToCanvas](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/fittocanvas-method/llms-full.txt) expands a shape to the size of the canvas when [CanFitToCanvas](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/shape/canfittocanvas-property/llms-full.txt) is `true`.

#### Change the Z-Order of Selected Shapes

The order of the shapes decides which one covers another. [Drawing.Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/llms-full.txt) changes it for the selected shapes:

| Method | Moves the selected shapes | Possible when |
|---|---|---|
| [BringForward](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/bringforward-method/llms-full.txt) | One level up | [CanBringForward](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/canbringforward-property/llms-full.txt) is `true` |
| [SendBackward](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/sendbackward-method/llms-full.txt) | One level down | [CanSendBackward](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/cansendbackward-property/llms-full.txt) is `true` |
| [BringToFront](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/bringtofront-method/llms-full.txt) | Above all other shapes; one shape only | [CanBringToFront](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/canbringtofront-property/llms-full.txt) is `true` |
| [SendToBack](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/sendtoback-method/llms-full.txt) | Below all other shapes; one shape only | [CanSendToBack](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/cansendtoback-property/llms-full.txt) is `true` |

A method has no effect while its `Can` property is `false`, for example when no shape is selected. The shapes of a drawing can be selected when the user has activated it with a click. The following button brings the selected shape of the activated drawing to the front; `Focusable="False"` keeps the keyboard focus in the editor while the button is clicked:

```xml
<Button Content="Bring to Front" Focusable="False" Click="bringToFrontButton_Click" />
```

```csharp
private void bringToFrontButton_Click(object sender, RoutedEventArgs e)
{
    // The drawing the user activated, or null
    DrawingFrame frame = textControl1.Drawings.GetActivatedItem();

    if (frame?.Drawing is TXDrawingControl drawing && drawing.Selection.CanBringToFront)
    {
        drawing.Selection.BringToFront();
    }
}
```

[DrawingCollection.GetActivatedItem](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/drawingcollection/getactivateditem-method/llms-full.txt) returns the activated drawing. [Selection.Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/selection/shapes-property/llms-full.txt) sets the selection in code, and [TXDrawingControl.SelectAll](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/selectall-method/llms-full.txt) selects every shape. The `TextControl` reports the activation with [DrawingActivated](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/drawingactivated-event/llms-full.txt), whose [DrawingEventArgs.DrawingFrame](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/drawingeventargs/drawingframe-property/llms-full.txt) is the drawing; its handler is the place to attach shape events to drawings loaded with a document.

#### Events and Members of the Drawing Control

| Member | Purpose |
|---|---|
| [ShapeCreated](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapecreated-event/llms-full.txt), [ShapeDeleted](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapedeleted-event/llms-full.txt) | A shape was added by pasting or `Add`, or removed by cutting or `Remove` |
| [ShapeSelected](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapeselected-event/llms-full.txt), [ShapeDeselected](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapedeselected-event/llms-full.txt), [ShapeClicked](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapeclicked-event/llms-full.txt) | A shape was selected, deselected or clicked |
| [ShapeMoved](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapemoved-event/llms-full.txt), [ShapeSized](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapesized-event/llms-full.txt), [ShapeFlipped](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapeflipped-event/llms-full.txt), [ShapeAdjusted](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapeadjusted-event/llms-full.txt) | The user moved, sized or flipped a shape with the mouse, or changed it with its yellow adjust handle |
| [ShapeFormatChanged](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/shapeformatchanged-event/llms-full.txt) | The fill, outline or type of a shape changed |
| [Changed](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/changed-event/llms-full.txt), [ViewChanged](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/viewchanged-event/llms-full.txt) | The number or formatting of the shapes changed, or the view changed, with the changed area in [ViewChangedEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/viewchangedeventargs/llms-full.txt) |
| [AdaptBounds](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/adaptbounds-event/llms-full.txt), [SizeToContent](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/sizetocontent-method/llms-full.txt) | The visible bounds of the shapes need a larger or smaller control, and the method that adapts the control to them |
| [IsCanvasVisible](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/iscanvasvisible-property/llms-full.txt) | `false` when the control holds a single shape that it represents, without a border or canvas of its own |
| [FormatShapesDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/formatshapesdialog-method/llms-full.txt) | Opens the dialog box that formats the selected shapes; returns `null` when no shape is selected |
| [Undo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/undo-method/llms-full.txt), [Redo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/redo-method/llms-full.txt), [Copy](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/copy-method/llms-full.txt), [Cut](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/cut-method/llms-full.txt), [Paste](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/paste-method/llms-full.txt) | Undo and clipboard operations for the shapes of the drawing |
| [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/zoomfactor-property/llms-full.txt), [BackColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/backcolor-property/llms-full.txt), [BorderColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/bordercolor-property/llms-full.txt), [BorderWidth](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/borderwidth-property/llms-full.txt) | The zoom factor of the drawing and the background and border of the canvas |
| [Save](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/save-method/llms-full.txt), [Load](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/load-method/llms-full.txt), [SaveImage](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf-drawing/txdrawingcontrol/saveimage-method/llms-full.txt) | Save the shape data to a stream and load it again, or save the shapes as an image |

#### TXDrawingCore

[TXDrawingCore](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/txdrawingcore/llms-full.txt), in `TXTextControl.Drawing` since version 33.0, is a canvas of shapes without a user interface. It has `Shapes`, `Selection`, most of the shape events and the undo and clipboard members of the drawing control, and renders the shapes as SVG with [GetSVG](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-drawing/txdrawingcore/getsvg-method/llms-full.txt). The [DrawingFrame constructor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/drawingframe/constructor/llms-full.txt) takes the drawing controls of Windows Forms and WPF, so a drawing inserted into the WPF `TextControl` uses `TXDrawingControl`.

### Create a Barcode as SVG With TXBarcodeCore

[TXBarcodeCore](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/llms-full.txt), in `TXTextControl.Barcode` since version 33.0, is the barcode counterpart of `TXDrawingCore`: a barcode without a WPF element. It has the type, text and appearance properties of `TXBarcodeControl` and returns the barcode as an SVG string, for example for a web page, an email or an image file. The [BarcodeFrame constructor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-datavisualization/barcodeframe/constructor/llms-full.txt) takes the barcode controls only, so a barcode that users should edit in the document is inserted as in [Insert a Barcode in Code](#insert-a-barcode-in-code). The SVG of a `TXBarcodeCore` goes into a document as an image:

```csharp
using System.IO;
using System.Windows;
using TXTextControl.Barcode;

private void insertSvgBarcodeButton_Click(object sender, RoutedEventArgs e)
{
    const string orderNumber = "ORD-2025-0042";

    // Initialize the new instance before using it
    TXBarcodeCore barcode = new TXBarcodeCore();
    barcode.Create();
    barcode.BarcodeType = BarcodeType.Code128;
    barcode.UpperTextLength = orderNumber.Length;
    barcode.Text = orderNumber;

    // The barcode as an SVG image; Size is System.Drawing.Size, not the WPF Size
    string svg = barcode.GetSVG(new System.Drawing.Size(4320, 1080));
    File.WriteAllText("order-barcode.svg", svg);

    // 8 is the import filter for SVG
    textControl1.Images.Add(new TXTextControl.Image("order-barcode.svg", 8), -1);
}
```

The code works as follows:

- [Create](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/create-method/llms-full.txt) initializes the object and must be called before any other member.
- [BarcodeType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/barcodetype-property/llms-full.txt) is set first, because [UpperTextLength](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/uppertextlength-property/llms-full.txt), the maximum number of characters, and [Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/text-property/llms-full.txt) throw an `ArgumentException` when the value isn't valid for the type.
- [GetSVG](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/getsvg-method/llms-full.txt) returns the SVG in the given size, which also becomes the [Size](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/size-property/llms-full.txt) of the object.
- The image is inserted inline at the input position, as [Images](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/images/#insert-an-image-from-code) describes. `TXTextControl.Image` is written in full because `Image` alone is the WPF image element. The result is an image in the document, not a barcode that `BarcodeLayoutDialog` or the ribbon can change.

Before you set `Text` from user input, the static [IsTextValid](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/istextvalid-method/llms-full.txt) tells whether a text is valid for a barcode type and returns the error message if not. [GetDefaultText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/getdefaulttext-method/llms-full.txt) returns a valid sample text, and [GetMinimumTextLength](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/getminimumtextlength-method/llms-full.txt) and [GetMaximumTextLength](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/getmaximumtextlength-method/llms-full.txt) the shortest and longest text of a type. [Save](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/save-method/llms-full.txt) writes the settings of the barcode to a file or a `Stream`, and [Load](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-barcode/txbarcodecore/load-method/llms-full.txt) reads them into a `TXBarcodeCore` again.

### Merge Data Into Barcodes

Barcodes in a template get their data in a mail merge, like merge fields. [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/images-barcodes/llms-full.txt) in the Mail Merge section shows how templates with barcodes are merged with `MailMerge`.

### Next Steps

- [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/charts-barcodes/llms-full.txt): barcodes from the user's side of the editor.
- [Text Frames and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/text-frames-shapes/llms-full.txt): shapes and drawings in the editor.
- [Charts and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/charts-barcodes/llms-full.txt) in Document Processing: barcodes in documents created with `ServerTextControl`.
- [Images and Barcodes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/images-barcodes/llms-full.txt): merge data into barcodes.

---

## Nearby

- **Previous:** [Integrating TX Spell .NET for WPF](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/tx-spell/llms-full.txt)
- **Next:** [DPI and Display Scaling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/dpi-scaling/llms-full.txt)
