--- title: "Intercepting Input from the Stylus" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "architecture [WPF], " - ", " - ", " - ", " ms.assetid: 791bb2f0-4e5c-4569-ac3c-211996808d44 --- # Intercepting Input from the Stylus The architecture provides a mechanism for implementing low-level control over input and the creation of digital ink objects. The class provides a mechanism for you to implement custom behavior and apply it to the stream of data coming from the stylus device for the optimal performance. This topic contains the following subsections: - [Architecture](#Architecture) - [Implementing Stylus Plug-ins](#ImplementingStylusPlugins) - [Adding Your Plug-in to an InkCanvas](#AddingYourPluginToAnInkCanvas) - [Conclusion](#Conclusion) ## Architecture The is the evolution of the [StylusInput](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/ms574861(v=vs.90)) APIs, described in [Accessing and Manipulating Pen Input](https://docs.microsoft.com/previous-versions/ms818317(v%3dmsdn.10)). Each has a property that is a . You can add a to an element's property to manipulate data as it is generated. data consists of all the properties supported by the system digitizer, including the and point data, as well as data. Your objects are inserted directly into the stream of data coming from the device when you add the to the property. The order in which plug-ins are added to the collection dictates the order in which they will receive data. For example, if you add a filter plug-in that restricts input to a particular region, and then add a plug-in that recognizes gestures as they are written, the plug-in that recognizes gestures will receive filtered data. ## Implementing Stylus Plug-ins To implement a plug-in, derive a class from . This class is applied o the stream of data as it comes in from the . In this class you can modify the values of the data. > [!CAUTION] > If a throws or causes an exception, the application will close. You should thoroughly test controls that consume a and only use a control if you are certain the will not throw an exception. The following example demonstrates a plug-in that restricts the stylus input by modifying the and values in the data as it comes in from the device. [!code-csharp[AdvancedInkTopicsSamples#19](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/DynamicRenderer.cs#19)] [!code-vb[AdvancedInkTopicsSamples#19](~/samples/snippets/visualbasic/VS_Snippets_Wpf/AdvancedInkTopicsSamples/VisualBasic/DynamicRenderer.vb#19)] [!code-csharp[AdvancedInkTopicsSamples#3](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/DynamicRenderer.cs#3)] [!code-vb[AdvancedInkTopicsSamples#3](~/samples/snippets/visualbasic/VS_Snippets_Wpf/AdvancedInkTopicsSamples/VisualBasic/DynamicRenderer.vb#3)] ## Adding Your Plug-in to an InkCanvas The easiest way to use your custom plug-in is to implement a class that derives from InkCanvas and add it to the property. The following example demonstrates a custom that filters the ink. [!code-csharp[AdvancedInkTopicsSamples#4](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/Window1.xaml.cs#4)] If you add a `FilterInkCanvas` to your application and run it, you will notice that the ink isn't restricted to a region until after the user completes a stroke. This is because the has a property, which is a and is already a member of the collection. The custom you added to the collection receives the data after receives data. As a result, the data will not be filtered until after the user lifts the pen to end a stroke. To filter the ink as the user draws it, you must insert the `FilterPlugin` before the . The following C# code demonstrates a custom that filters the ink as it is drawn. [!code-csharp[AdvancedInkTopicsSamples#5](~/samples/snippets/csharp/VS_Snippets_Wpf/AdvancedInkTopicsSamples/CSharp/Window1.xaml.cs#5)] ## Conclusion By deriving your own classes and inserting them into collections, you can greatly enhance the behavior of your digital ink. You have access to the data as it is generated, giving you the opportunity to customize the input. Because you have such low-level access to the data, you can implement ink collection and rendering with optimal performance for your application. ## See also - [Advanced Ink Handling](advanced-ink-handling.md) - [Accessing and Manipulating Pen Input](https://docs.microsoft.com/previous-versions/ms818317(v%3dmsdn.10))