Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-add-custom-data-to-ink-data.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

78 lines
2.7 KiB
Markdown

---
title: "How to: Add Custom Data to Ink Data"
ms.date: "03/30/2017"
helpviewer_keywords:
- "ink data [WPF], adding custom data"
- "InkCanvas [WPF], displaying"
ms.assetid: f02aac6f-3436-4f7c-b6ea-0452cba5332c
---
# How to: Add Custom Data to Ink Data
You can add custom data to ink that will be saved when the ink is saved as ink serialized format (ISF). You can save the custom data to the <xref:System.Windows.Ink.DrawingAttributes>, the <xref:System.Windows.Ink.StrokeCollection>, or the <xref:System.Windows.Ink.Stroke>. Being able to save custom data on three objects gives you the ability to decide the best place to save the data. All three classes use similar methods to store and access custom data.
Only the following types can be saved as custom data:
- <xref:System.Boolean>
- <xref:System.Boolean>[]
- <xref:System.Byte>
- <xref:System.Byte>[]
- <xref:System.Char>
- <xref:System.Char>[]
- <xref:System.DateTime>
- <xref:System.DateTime>[]
- <xref:System.Decimal>
- <xref:System.Decimal>[]
- <xref:System.Double>
- <xref:System.Double>[]
- <xref:System.Int16>
- <xref:System.Int16>[]
- <xref:System.Int32>
- <xref:System.Int32>[]
- <xref:System.Int64>
- <xref:System.Int64>[]
- <xref:System.Single>
- <xref:System.Single>[]
- <xref:System.String>
- <xref:System.UInt16>
- <xref:System.UInt16>[]
- <xref:System.UInt32>
- <xref:System.UInt32>[]
- <xref:System.UInt64>
- <xref:System.UInt64>[]
## Example
The following example demonstrates how to add and retrieve custom data from a <xref:System.Windows.Ink.StrokeCollection>.
[!code-csharp[HowToAddCustomDataToInk#1](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToAddCustomDataToInk/CSharp/Window1.xaml.cs#1)]
The following example creates an application that displays an <xref:System.Windows.Controls.InkCanvas> and two buttons. The button, `switchAuthor`, enables two pens to be used by two different authors. The button `changePenColors` changes the color of each stroke on the <xref:System.Windows.Controls.InkCanvas> according to the author. The application defines two <xref:System.Windows.Ink.DrawingAttributes> objects and adds a custom property to each one that indicates which author drew the <xref:System.Windows.Ink.Stroke>. When the user clicks `changePenColors`, the application changes the appearance of the stroke according to the value of the custom property.
[!code-xaml[HowToAddCustomDataToInk#2](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToAddCustomDataToInk/CSharp/Window1.xaml#2)]
[!code-csharp[HowToAddCustomDataToInk#3](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToAddCustomDataToInk/CSharp/Window1.xaml.cs#3)]