StylusPlugIn Klas
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Vertegenwoordigt een invoegtoepassing die kan worden toegevoegd aan de eigenschap van StylusPlugIns een besturingselement.
public ref class StylusPlugIn abstract
public abstract class StylusPlugIn
type StylusPlugIn = class
Public MustInherit Class StylusPlugIn
- Overname
-
StylusPlugIn
- Afgeleid
Voorbeelden
In het volgende voorbeeld wordt een aangepaste sjabloon StylusPlugIn gemaakt waarmee de inkt wordt beperkt tot een bepaald gebied in het besturingselement.
// EventArgs for the StrokeRendered event.
public class StrokeRenderedEventArgs : EventArgs
{
StylusPointCollection strokePoints;
public StrokeRenderedEventArgs(StylusPointCollection points)
{
strokePoints = points;
}
public StylusPointCollection StrokePoints
{
get
{
return strokePoints;
}
}
}
// EventHandler for the StrokeRendered event.
public delegate void StrokeRenderedEventHandler(object sender, StrokeRenderedEventArgs e);
// A StylusPlugin that restricts the input area
class FilterPlugin : StylusPlugIn
{
StylusPointCollection collectedPoints;
int currentStylus = -1;
public event StrokeRenderedEventHandler StrokeRendered;
protected override void OnStylusDown(RawStylusInput rawStylusInput)
{
// Run the base class before modifying the data
base.OnStylusDown(rawStylusInput);
if (currentStylus == -1)
{
StylusPointCollection pointsFromEvent = rawStylusInput.GetStylusPoints();
// Create an emtpy StylusPointCollection to contain the filtered
// points.
collectedPoints = new StylusPointCollection(pointsFromEvent.Description);
// Restrict the stylus input and add the filtered
// points to collectedPoints.
StylusPointCollection points = FilterPackets(pointsFromEvent);
rawStylusInput.SetStylusPoints(points);
collectedPoints.Add(points);
currentStylus = rawStylusInput.StylusDeviceId;
}
}
protected override void OnStylusMove(RawStylusInput rawStylusInput)
{
// Run the base class before modifying the data
base.OnStylusMove(rawStylusInput);
if (currentStylus == rawStylusInput.StylusDeviceId)
{
StylusPointCollection pointsFromEvent = rawStylusInput.GetStylusPoints();
// Restrict the stylus input and add the filtered
// points to collectedPoints.
StylusPointCollection points = FilterPackets(pointsFromEvent);
rawStylusInput.SetStylusPoints(points);
collectedPoints.Add(points);
}
}
protected override void OnStylusUp(RawStylusInput rawStylusInput)
{
// Run the base class before modifying the data
base.OnStylusUp(rawStylusInput);
if (currentStylus == rawStylusInput.StylusDeviceId)
{
StylusPointCollection pointsFromEvent = rawStylusInput.GetStylusPoints();
// Restrict the stylus input and add the filtered
// points to collectedPoints.
StylusPointCollection points = FilterPackets(pointsFromEvent);
rawStylusInput.SetStylusPoints(points);
collectedPoints.Add(points);
// Subscribe to the OnStylusUpProcessed method.
rawStylusInput.NotifyWhenProcessed(collectedPoints);
currentStylus = -1;
}
}
private StylusPointCollection FilterPackets(StylusPointCollection stylusPoints)
{
// Modify the (X,Y) data to move the points
// inside the acceptable input area, if necessary
for (int i = 0; i < stylusPoints.Count; i++)
{
StylusPoint sp = stylusPoints[i];
if (sp.X < 50) sp.X = 50;
if (sp.X > 250) sp.X = 250;
if (sp.Y < 50) sp.Y = 50;
if (sp.Y > 250) sp.Y = 250;
stylusPoints[i] = sp;
}
// Return the modified StylusPoints.
return stylusPoints;
}
// This is called on the application thread.
protected override void OnStylusUpProcessed(object callbackData, bool targetVerified)
{
// Check that the element actually receive the OnStylusUp input.
if (targetVerified)
{
StylusPointCollection strokePoints = callbackData as StylusPointCollection;
if (strokePoints == null)
{
return;
}
// Raise the StrokeRendered event so the consumer of the plugin can
// add the filtered stroke to its StrokeCollection.
StrokeRenderedEventArgs e = new StrokeRenderedEventArgs(strokePoints);
OnStrokeRendered(e);
}
}
protected virtual void OnStrokeRendered(StrokeRenderedEventArgs e)
{
if (StrokeRendered != null)
{
StrokeRendered(this, e);
}
}
}
' EventArgs for the StrokeRendered event.
Public Class StrokeRenderedEventArgs
Inherits EventArgs
Private currentStrokePoints As StylusPointCollection
Public Sub New(ByVal points As StylusPointCollection)
currentStrokePoints = points
End Sub
Public ReadOnly Property StrokePoints() As StylusPointCollection
Get
Return currentStrokePoints
End Get
End Property
End Class
' EventHandler for the StrokeRendered event.
Public Delegate Sub StrokeRenderedEventHandler(ByVal sender As Object, ByVal e As StrokeRenderedEventArgs)
' A StylusPlugin that restricts the input area
Class FilterPlugin
Inherits StylusPlugIn
Private collectedPoints As StylusPointCollection
Private currentStylus As Integer = -1
Public Event StrokeRendered As StrokeRenderedEventHandler
Protected Overrides Sub OnStylusDown(ByVal rawStylusInput As RawStylusInput)
' Run the base class before we modify the data
MyBase.OnStylusDown(rawStylusInput)
If currentStylus = -1 Then
Dim pointsFromEvent As StylusPointCollection = rawStylusInput.GetStylusPoints()
' Create an emtpy StylusPointCollection to contain the filtered
' points.
collectedPoints = New StylusPointCollection(pointsFromEvent.Description)
' Restrict the stylus input and add the filtered
' points to collectedPoints.
Dim points As StylusPointCollection = FilterPackets(pointsFromEvent)
rawStylusInput.SetStylusPoints(points)
collectedPoints.Add(points)
currentStylus = rawStylusInput.StylusDeviceId
End If
End Sub
Protected Overrides Sub OnStylusMove(ByVal rawStylusInput As RawStylusInput)
' Run the base class before we modify the data
MyBase.OnStylusMove(rawStylusInput)
If currentStylus = rawStylusInput.StylusDeviceId Then
Dim pointsFromEvent As StylusPointCollection = rawStylusInput.GetStylusPoints()
' Restrict the stylus input and add the filtered
' points to collectedPoints.
Dim points As StylusPointCollection = FilterPackets(pointsFromEvent)
rawStylusInput.SetStylusPoints(points)
collectedPoints.Add(points)
End If
End Sub
Protected Overrides Sub OnStylusUp(ByVal rawStylusInput As RawStylusInput)
' Run the base class before we modify the data
MyBase.OnStylusUp(rawStylusInput)
If currentStylus = rawStylusInput.StylusDeviceId Then
Dim pointsFromEvent As StylusPointCollection = rawStylusInput.GetStylusPoints()
' Restrict the stylus input and add the filtered
' points to collectedPoints.
Dim points As StylusPointCollection = FilterPackets(pointsFromEvent)
rawStylusInput.SetStylusPoints(points)
collectedPoints.Add(points)
RecordPoints(collectedPoints, "collectPoints - StylusUp")
' Subscribe to the OnStylusUpProcessed method.
rawStylusInput.NotifyWhenProcessed(collectedPoints)
currentStylus = -1
End If
End Sub
Private Function FilterPackets(ByVal stylusPoints As StylusPointCollection) As StylusPointCollection
' Modify the (X,Y) data to move the points
' inside the acceptable input area, if necessary.
Dim i As Integer
For i = 0 To stylusPoints.Count - 1
Dim sp As StylusPoint = stylusPoints(i)
If sp.X < 50 Then
sp.X = 50
End If
If sp.X > 250 Then
sp.X = 250
End If
If sp.Y < 50 Then
sp.Y = 50
End If
If sp.Y > 250 Then
sp.Y = 250
End If
stylusPoints(i) = sp
Next i
' Return the modified StylusPoints.
Return stylusPoints
End Function 'FilterPackets
' This is called on the application thread.
Protected Overrides Sub OnStylusUpProcessed(ByVal callbackData As Object, _
ByVal targetVerified As Boolean)
' Check that the element actually receive the OnStylusUp input.
If targetVerified Then
Dim strokePoints As StylusPointCollection
strokePoints = CType(callbackData, StylusPointCollection)
If strokePoints Is Nothing Then
Return
End If
' Raise the StrokeRendered event so the consumer of the plugin can
' add the filtered stroke to its StrokeCollection.
RecordPoints(strokePoints, "onStylusUpProcessed")
Dim e As New StrokeRenderedEventArgs(strokePoints)
OnStrokeRendered(e)
End If
End Sub
Protected Overridable Sub OnStrokeRendered(ByVal e As StrokeRenderedEventArgs)
RaiseEvent StrokeRendered(Me, e)
End Sub
Public Sub RecordPoints(ByVal points As StylusPointCollection, ByVal name As String)
System.Diagnostics.Debug.WriteLine(name)
For Each point As StylusPoint In points
System.Diagnostics.Debug.WriteLine(" x: " & point.X & " y: " & point.Y)
Next
End Sub
End Class
Opmerkingen
Hiermee StylusPlugIn kunt u objecten op afzonderlijke threads bewerken StylusPoint . Afzonderlijke threads worden gebruikt zodat de inkt nog steeds wordt weergegeven als de gegevens van de tabletpen, zelfs als de toepassing iets anders doet.
Als u styluspunten van de hardware wilt onderscheppen, maakt u een klasse die van de StylusPlugIn klasse overkomt. De StylusPlugIn klasse heeft de volgende methoden die u kunt overschrijven om objecten op een thread in de penthreadpool te bewerken StylusPoint .
De invoer van de pen wordt doorgestuurd naar een element StylusPlugIn op de penthread. Omdat nauwkeurige treffers niet op de penthread kunnen worden uitgevoerd, kunnen sommige elementen af en toe stylusinvoer ontvangen die is bedoeld voor andere elementen. Als u wilt controleren of de invoer correct is gerouteerd voordat u een bewerking uitvoert, abonneert u zich op de bewerking en voert u deze uit in de OnStylusDownProcessed, OnStylusMoveProcessedof OnStylusUpProcessed methode. Deze methoden worden aangeroepen door de hoofdtoepassingsthread nadat nauwkeurige hittests zijn uitgevoerd. Als u zich wilt abonneren op deze methoden, roept u de NotifyWhenProcessed methode aan in de methode die op de penthread voorkomt. Als u bijvoorbeeld inbelt NotifyWhenProcessedOnStylusMove, gebeurt dit OnStylusMoveProcessed .
Note
Als u een StylusPlugIn binnenste besturingselement gebruikt, moet u de invoegtoepassing en het besturingselement uitgebreid testen om ervoor te zorgen dat ze geen onbedoelde uitzonderingen genereren.
XAML-tekstgebruik
Deze klasse wordt doorgaans niet gebruikt in XAML.
Constructors
| Name | Description |
|---|---|
| StylusPlugIn() |
Initialiseert een nieuw exemplaar van de StylusPlugIn klasse. |
Eigenschappen
| Name | Description |
|---|---|
| Element |
Hiermee haalt u de UIElement waaraan de StylusPlugIn bijlage is gekoppeld. |
| ElementBounds |
Hiermee haalt u de in de cache opgeslagen grenzen van het element op. |
| Enabled |
Hiermee haalt u op of stelt u in of het StylusPlugIn actief is. |
| IsActiveForInput |
Hiermee wordt aangegeven of de StylusPlugIn invoer kan worden geaccepteerd. |
Methoden
| Name | Description |
|---|---|
| Equals(Object) |
Bepaalt of het opgegeven object gelijk is aan het huidige object. (Overgenomen van Object) |
| GetHashCode() |
Fungeert als de standaardhashfunctie. (Overgenomen van Object) |
| GetType() |
Hiermee haalt u de Type huidige instantie op. (Overgenomen van Object) |
| MemberwiseClone() |
Hiermee maakt u een ondiepe kopie van de huidige Object. (Overgenomen van Object) |
| OnAdded() |
Treedt op wanneer de StylusPlugIn wordt toegevoegd aan een element. |
| OnEnabledChanged() |
Treedt op wanneer de Enabled eigenschap wordt gewijzigd. |
| OnIsActiveForInputChanged() |
Treedt op wanneer de IsActiveForInput eigenschap wordt gewijzigd. |
| OnRemoved() |
Treedt op wanneer de StylusPlugIn wordt verwijderd uit een element. |
| OnStylusDown(RawStylusInput) |
Vindt plaats op een draad in de penthreadpool wanneer de tabletpen de digitalisatiefunctie aanraakt. |
| OnStylusDownProcessed(Object, Boolean) |
Vindt plaats op de thread van de toepassingsgebruikersinterface (gebruikersinterface) wanneer de tabletpen de digitalisatiefunctie aanraakt. |
| OnStylusEnter(RawStylusInput, Boolean) |
Treedt op een penthread op wanneer de cursor de grenzen van een element binnenkomt. |
| OnStylusLeave(RawStylusInput, Boolean) |
Treedt op een penthread op wanneer de cursor de grenzen van een element verlaat. |
| OnStylusMove(RawStylusInput) |
Treedt op een pendraad op wanneer de tabletpen op de digitaliserende pen beweegt. |
| OnStylusMoveProcessed(Object, Boolean) |
Vindt plaats op de thread van de toepassingsgebruikersinterface (gebruikersinterface) wanneer de tabletpen op de digitaler wordt verplaatst. |
| OnStylusUp(RawStylusInput) |
Treedt op een penthread op wanneer de gebruiker de tabletpen uit de digitaliserende pen haalt. |
| OnStylusUpProcessed(Object, Boolean) |
Vindt plaats op de thread van de toepassingsgebruikersinterface (gebruikersinterface) wanneer de gebruiker de tabletpen uit de digitalisatiefunctie haalt. |
| ToString() |
Retourneert een tekenreeks die het huidige object vertegenwoordigt. (Overgenomen van Object) |